当前位置:网站首页>[first song] rebirth of me in py introductory training (4): Circular program
[first song] rebirth of me in py introductory training (4): Circular program
2022-07-27 06:05:00 【Collapse an old face】
It's not easy to create , Before reference , Point a praise , Collection , You can't pay too much attention , Family
The first 1 Turn off : Output diamond character pattern
Programming requirements
According to the prompt , Add code to the editor on the right , And output diamond pattern .
Be careful :
The last line of diamond pattern does not need to wrap , You can use the following format to remove line breaks :
print("*" ,end = "")# Output the upper half of the diamond , The lower half is output directly through reverse control #********* Begin *********# for n in range( row-1, 0, -1): i = 2 * n - 1 # Every line * The number of j = ( row - n ) * 2 # The number of spaces in each line for jj in range(j): # Controls the space of each line of output print( " ", end="" ) if i > 1: # If a line of letters * The number of is greater than 1, Control * and * Space format between and then output for ii in range(i): if ii != i - 1: print("* ", end="" ) else: print("*") else: # If a line of letters * The number of is equal to 1, Direct output * print("*") #********* End *********#The first 2 Turn off : Output even numbers in the specified range
Programming requirements
Enter two integers , Two numbers as a range , Output all even numbers in the range through the program .
for example :
Input :1 12, The output :2,4,6,8,10,12; Input :-2 10, The output :-2,0,2,4,6,8,10; Input :100 110, The output :100,102,104,106,108,110.Be careful :
print()Output does not wrap .
# -*- coding:utf-8 -*-
begin, end = map( int, input("").split() )
result = []
#********* Begin *********#
abc = []
for x in range(begin,end+1):
result.append(x)
for i in result:
if i % 2 == 0:
abc.append(i)
print(','.join(map(str,abc)))
#********* End *********#The first 3 Turn off : Output the multiplication table
Programming requirements
Demand the use of for Loop out the multiplication table , Through double layer for Cycle to control , Then output the 99 multiplication table in the corresponding format .
- Pay attention to line feed .
# -*- coding:utf-8 -*-
for i in range(1,10):
for j in range(i):
#********* Begin *********#
if i == j+1:
print('{} * {} = {}'.format(i, j+1, i*(j+1)),end='')
continue
print('{} * {} = {} '.format(i, j+1, i*(j+1)),end='')
#********* End *********#
if i != 9:
print()The first 4 Turn off : stone 、 scissors 、 Cloth game
Programming requirements
Write traditional stones 、 scissors 、 Cloth's game program , The rule of a single game is , Scissors are better than cloth , Busson stone , Stone is better than scissors . User players compete with computers , use 7 game 4 To win . For simplicity and convenience , The choice of computer is fixed , It's not a random selection sequence , Finally, output the victory or draw information .
for example :
Input : stone , scissors , scissors , cloth , cloth , stone , stone , The output : Computers win !;
Input : scissors , cloth , scissors , stone , cloth , scissors , stone , The output : Computers win !;
Input : cloth , stone , stone , cloth , scissors , stone , scissors , The output : Game player wins ! .
#********* Begin *********#
for x in range(0,7):
if [guess_list[x],people_guess[x]] == computer_win_condition[0]:
computer_win_number += 1
elif [guess_list[x],people_guess[x]] == computer_win_condition[1]:
computer_win_number += 1
elif [guess_list[x],people_guess[x]] == computer_win_condition[2]:
computer_win_number += 1
elif people_guess[x] == guess_list[x]:
computer_win_number += 1
people_win_number += 1
else:
people_win_number += 1
#********* End *********#
notes : The content is only for reference and sharing , Do not spread without permission , Tort made delete
边栏推荐
猜你喜欢

Digital image processing Chapter 5 - image restoration and reconstruction

数字图像处理——第六章 彩色图像处理

韦东山 数码相框 项目学习(四)简易的TXT文档显示器(电纸书)

Greedy high performance neural network and AI chip application research and training

Numpy basic learning

2021-06-26

Stm32-fsmc extended memory SRAM

【Arduino】重生之Arduino 学僧(1)

Digital image processing Chapter 2 fundamentals of digital image
![[Haowen planting grass] knowledge of root domain name - Ruan Yifeng's Weblog](/img/75/8f41db9f9c077b43751d63b7b5b57e.png)
[Haowen planting grass] knowledge of root domain name - Ruan Yifeng's Weblog
随机推荐
物联网操作系统
【头歌】重生之我在py入门实训中(9):异常处理
韦东山 数码相框 项目学习(三)freetype的移植
Essential tool for making video special effects: nuke 13
芯片、存储器及其关键指标简述 一
Matlab 画图(超详细)
16. Over fitting and under fitting
【11】二进制编码:“手持两把锟斤拷,口中疾呼烫烫烫”?
剪枝-量化-转onnx中文系列教程
Xmind 思维导图 2022 v12.0.3中文版更新了哪些内容?
10. Gradient, activation function and loss
韦东山 数码相框 项目学习(二)在LCD上显示中文字符
数字图像处理第五章——图像复原与重建
物联网操作系统多任务基础
15. GPU acceleration, Minist test practice and visdom visualization
【头歌】重生之我在py入门实训中(8): 模块
6. Dimension transformation and broadcasting
回调使用lambda
[Haowen planting grass] knowledge of root domain name - Ruan Yifeng's Weblog
制作视频特效必备工具:NUKE 13