gpt4 book ai didi

python - 简单 if 条件的语法错误(如果 partychoice = R :)

转载 作者:太空宇宙 更新时间:2023-11-04 02:53:22 24 4
gpt4 key购买 nike

新程序员,使用 python 2.7。

使用此代码,我在“if partychoice = R, stating the '=' is invalid syntax”行中收到语法错误。怎么会不让我分配变量。

此外,我确定还有很多其他错误,但我必须从某个地方开始。

print "Welcome to 'Pass the Bill', where you will take on the role of a professional lobbyist trying to guide a bill through Congress and get it signed into law by the President!"
start = raw_input(str ('Press Y to continue:'))
print 'Great, lets get started!'
partychoice = raw_input (str("Would you like to be a Republican or Democrat? Type 'R' for Republican or 'D' for Democrat."))
if partychoice = R:
print 'Ah, the Grand old Party of Lincoln and Reagan. Great Choice!'
replegchoice = raw_input (str("What type of bill what you like congress to introduce? Restrictions on abortions, lower income taxes, easier access to automatic weapons, private health plans, or stricter immigration laws? ( A = abortion restrictions, L = lower taxes, AW = automatic weapons, H = private health plans, S = stricter immigration laws'))
if replegchoice = A or a
print 'A controversial choice, despite support of most Republicans, you are sure to face opposition from Democrats in Congress!'
if replegchoice = L or l
print 'A popular idea, Republicans in Congress are sure to support this idea, as will many American voters!'
if replegchoice = AW, aw, Aw, or AW
print 'Rural, midwest, and small town voters will love this, as will most Republicans in Congress. Democrats and voters in urban cities will surely be less supportive.'
if replegchoice = H or h
print 'Eimination of Medicare, Medicaid, and Obamacare! Republicans generally like the idea of making each person responsible for paying their own health care costs'
if replegchoice = S or s
print 'a popular idea supported by president Trump, this is sure face strong opposition from democrats and many voters.'

谢谢大家

最佳答案

将行改为

if partychoice == 'R':

首先您需要使用两个“=”字符。一个'='设置一个变量,两个比较是否相等。

其次,您要将变量 partychoice 与字符串“R”进行比较,因此您需要引号。如果没有引号,它会认为您正在比较对另一个对象的引用。

关于python - 简单 if 条件的语法错误(如果 partychoice = R :),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43163531/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com