我希望某人有 7/10 的机会成功完成一项动作,例如爬墙。我无法让一组整数与 random.randint 一起使用,所以我不得不重新输入 10 次,如下所示:
import random
print('You try to climb the wall.')
climbResult = random.randint(1,10)
elif climbResult == (1):
print('You were successful.')
elif climbResult == (2):
print('You were successful.')
elif climbResult == (3):
print('You were successful.')
elif climbResult == (4):
print('You were successful.')
elif climbResult == (5):
print('You were successful.')
elif climbResult == (6):
print('You were successful.')
elif climbResult == (7):
print('You were successful.')
elif climbResult == (8):
print('You were unsuccessful.')
elif climbResult == (9):
print('You were unsuccessful.')
elif climbResult == (10):
print('You were unsuccessful.')
一遍又一遍地添加数字很痛苦,而这只有 10 个部分。我只想做两个 if 语句,一个有 70% 的机会打印你成功,另一个有 30% 的机会打印你不成功。
很抱歉,这是一个非常简单的问题,我问的方式可能很难理解。我只学了两个星期的 Python,我很难用英语问它,因为它不是我的第一语言。