Py学习  »  Python

除了使用Python的集合之外,还使用If-Else语句

Nath • 4 年前 • 1854 次点击  

我必须为学校创造一个算命师。我希望用户输入一个介于1-9之间的数字。但如果他们输入了不同的号码,我也想给出一个错误信息。我使用的是一个包含数字的集合,但我不能在if语句中调用它。

fortune_num = set([1, 2, 3, 4, 5, 6, 7, 8, 9])
user_num = input(f'Pick a number and find your fortune! Choose a number from 1 to 9 and hit enter: ')
print()
if user_num == fortune_num:
    print(user_num)
else:
    print('Error')
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/133150
文章 [ 4 ]  |  最新文章 4 年前