当前位置:网站首页>[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
边栏推荐
- 回调使用lambda
- cycleGAN解析
- 【头歌】重生之我在py入门实训中(5):列表
- 李宏毅 2020 深度学习与人类语言处理 DLHLP-Coreference Resolution-p21
- 【12】理解电路:从电报机到门电路,我们如何做到“千里传信”?
- 韦东山 数码相框 项目学习(四)简易的TXT文档显示器(电纸书)
- 12. Optimization problem practice
- What has been updated in the Chinese version of XMIND mind map 2022 v12.0.3?
- 数字图像处理——第三章 灰度变换与空间滤波
- pytorch中交叉熵损失函数的细节
猜你喜欢

12. Optimization problem practice

数字图像处理第五章——图像复原与重建

10. Gradient, activation function and loss

IOT operating system

安装windows下的redis

QGIS系列(1)-QGIS(server-apache) win10安装

Chrome 如何快速将一组正在浏览的网页(tabs)转移到另一台设备(电脑)上
![[concurrent programming series 9] priorityblockingqueue, delayqueue principle analysis of blocking queue](/img/2b/1bfadbffad33f8560357fab74e8308.png)
[concurrent programming series 9] priorityblockingqueue, delayqueue principle analysis of blocking queue

cycleGAN解析

AE 3D粒子系统插件:Trapcode Particular
随机推荐
6. Dimension transformation and broadcasting
[MySQL learning] 8
leetcode系列(一):买卖股票
Only one looper may be created per thread
AE 3D particle system plug-in: Trapcode particle
Gbase 8C - SQL reference 6 SQL syntax (6)
维度问题以及等高线
WebODM win10安装教程(亲测)
[high concurrency] interviewer
向量和矩阵的范数
Numpy basic learning
14. Example - Multi classification problem
韦东山 数码相框 项目学习(四)简易的TXT文档显示器(电纸书)
socket编程二:使用select
Digital image processing Chapter 2 fundamentals of digital image
李宏毅 2020 深度学习与人类语言处理 DLHLP-Conditional Generation by RNN and Attention-p22
VSCode解决运行ipynb文件使用卡顿问题
pytorch使用data_prefetcher提升数据读取速度
arcgis for js api(2) 获取要素服务的id集合
Gbase 8C - SQL reference 6 SQL syntax (14)