[Introduction to python tutorial] Self-learning Python: user input INPUT

Continue the following work with user input. You can use INPUT, users can enter their own information according to the prompt content, and then get corresponding feedback.

Enter code:

xm=input('Please enter your name:')

print ('Hello, '+xm+'!!!')

Results of the:

please enter your name:

It will wait for your input here, and when you have finished entering the content, the following content will be displayed.

Please enter your name: Zhang San

Hi Zhangsan!!!

Add an IF condition, and write a reminder that asks the number of diners and reports whether there are vacancies.

Enter code:

rs=input('Please input the number of diners:')

rs=int(rs)

if rs>=8:

print('\nCongratulations, there are still vacancies!')

else:

print('Sorry, there are no more spaces!')

Results of the:

According to the number of people entered, the corresponding result will be prompted. If the number of people is greater than or equal to 8, it will prompt that there are vacancies.

Please enter the number of people to eat: 7

Sorry, there are no more vacancies!

Please enter the number of people to eat: 9

Congratulations, there are still seats left!

END

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326799297&siteId=291194637