Python初学者之路--用户的输入以及while循环(1)

''' 用户输入以及while循环'''

message=input('Tell me something and I will return it to you in another way:')

'''input() 括号内为input要接受的参数 即向用户的提示或者说明'''

print(message)

'''如果需要提示的有多行 可以将提示语先存入变量 赋个input'''

prompt='If you tell us who you are,we can personalize the message you see'
prompt+='\n What is your name:'
message=input(prompt)
print(message)

age=input('How old are you?')
age=int(age)
if age >=18:                    #input输入值类型为 str型 ,需要进行类型转换才能和int比较
    print('Godd')
else:
    print('Badd9')
 

```python
prompt='添加一种配料:'
while True:
    message=input(prompt)
    if message=='quit':
        break
    else:
        print('\n',message,'我们会添加这种配料')

prompt1='How old are you?'
prompt1+='\nPlease enter your age:'
flag=True
while flag:
    age=int(input(prompt1))
    
    if age<=0:
        break
    if age<=3:
        print('Free')
    if (age>3)&(age<=6):
        print('3 dollar')
    else:
        print('10 dollar')

你可能感兴趣的:(Python初学者之路--用户的输入以及while循环(1))