这是我最近开始编写的代码:
import random
Q1 = input('''would you like to put your own words instead
of heads or tails if so say yes if not say no,
if you said no i will exit the code?''')
if 'Q1 = yes':
Q2 = input('''what word(s) or numbers(s) would
you like to use in your random
word or number picker?(also no
spaces in between numbers.)''')
y = random.choice(list(Q2))
print(y)
elif 'Q1 = no':
print(bye)发布于 2022-06-28 19:33:11
看看这一行:
if 'Q1 = yes':请注意,您正在使用字符串作为if条件。因此,它始终是一个True语句。
相反,请使用以下内容:
if Q1 == 'yes':发布于 2022-06-28 19:35:22
有许多语法错误,更正如下:
import random
Q1 = input(
"""would you like to put your own words instead
of heads or tails if so say yes if not say no,
if you said no i will exit the code?"""
)
if Q1 == "yes": # you need to check equality with `==` between values/variable containing value
Q2 = input( # Indentation should be consistent across the file as python is sensitive to indent
"""what word(s) or numbers(s) would
you like to use in your random
word or number picker?(also no
spaces in between numbers.)"""
)
y = random.choice(list(Q2))
print(y)
elif Q1 == "no":
print("bye")https://stackoverflow.com/questions/72792155
复制相似问题