python--用户的输入和while 循环

'''
函数函 input() 的工作原理 的
函数input() 让程序暂停运行,等待用户输入一些文本。获取用户输入后,Python将其存储在一个变量中,以方便你使用。
'''
# message = input("please tell me your name: ")
# print("hello "+message)
'''please tell me your name: claire
hello claire'''
# 7-1 汽车租赁 汽 :编写一个程序,询问用户要租赁什么样的汽车,并打印一条消息,如“Let me see if I can find you a Subaru”。
# car=input("what car do you want to rent:")
# print("Let me see if I can find you a Subaru")
# 7-2 餐馆订位 餐 :编写一个程序,询问用户有多少人用餐。如果超过8人,就打印一条消息,指出没有空桌;否则指出有空桌。
# order_count=input("how many people will have dinner:")
# order_count=int(order_count)
# if order_count > 8:
# print("there is no blank desk!please wait")
# else:
# print("welcome, come in please!")
# 7-3 10的整数倍 的 :让用户输入一个数字,并指出这个数字是否是10的整数倍。
# number=input("please input one number: ")
# number=int(number)
# if number%10==0:
# print(str(number)+"是10的倍数")
# else:
# print(str(number)+"不是10的倍数")
'''
for循环用于针对集合中的每个元素都一个代码块,而while循环不断的运行,直到指定的条件不满足为止'''
# current_number=1
# while current_number<=5:
# print(current_number)
# current_number+=1
'''可使用while 循环让程序在用户愿意时不断地运行,如下面的程序parrot.py所示。我们在其中定义了一个退出值,只要用户输入的不是这个值,程序就接着运行:'''
# prompt="\nplease tell me something, i will repeat to you: "
# prompt+="\nenter'quit' will end this program \t"
# message=''
# while message != "quit":
# message=input(prompt)
# if message !="quit":
# print(message)
# number=input("please input the count: ")
# i=1
# while i <=int(number):
# print("I love you !")
# i+=1
'''计算1-100 的和'''
# i=1 #计数器
# sum=0 #定义最终的变量
# while i <= 100:
# sum=sum+i
# i+=1
# print("1-100的和:"+str(sum))

'''计算1-100 所有偶数的和'''
# i=1 #计数器
# sum=0 #定义最终的变量
# while i <= 100:
# if i%2==0:
# sum=sum+i
# i+=1
# print("1-100偶数的和:"+str(sum))
#方法2
# i=0 #计数器
# sum=0 #定义最终的变量
# while i <= 100:
# sum=sum+i
# i+=2
# print("1-100偶数的和:"+str(sum))

'''练习:打印小星星
*
* *
* * *
* * * *
* * * * *
'''
# i = 1
# while i <=5:
# print("* "*i)
# i+=1
#自己定义要多少行的星星
# count=input("please inpput the count: ")
# count=int(count)
# i=1
# while i<=count:
# print("* "*i)
# i+=1
#九九乘法

# for i in range(1, 10):
# for j in range(1, i+1):
# print('{}x{}={}\t'.format(j, i, i*j), end='')
# print()
row=1
while row <= 9:
col=1
while col <=row:
print('%dx%d=%d'%(row,col,row*col),end=' ') #法1:格式化输出
# print(f'{row}x{col}={row*col}', end=' ') #法2:f 表达式
# print('{}x{}={}\t'.format(col, row, col*row), end='') #法3:format
col+=1
print()
row+=1






posted @ 2024-04-12 18:00  正霜霜儿  阅读(2)  评论(0编辑  收藏  举报