[英]How to repeat and replace data in a while loop python
该项目随机生成 A 和 B 并比较它们,我可以重复循环,但是,在下一个比较中 1. 如果 A 正确,我希望它保留并生成新的 B,2. 如果 B 正确,B成为新的 A 并生成新的 B。 注意:格式数据是已定义的 function 未显示
followers_a = account_a.get("follower_count")
followers_b = account_b.get("follower_count")
end_game = False
while not end_game:
print(f"Compare A: {format_data(account_a)}")
print(vs)
print(f"Against B {format_data(account_b)}")
guess = input("Who has more followers? Type 'A' or 'B': ").upper()
current_score = 0
if guess == "A":
if followers_a > followers_b:
current_score += 1
print(f"You are right! Current score: {current_score}")
else:
print(f"Sorry, that's wrong, Final score: {current_score}")
end_game = True
elif guess == "B":
if followers_b > followers_a:
print(f"You are right! Current score: {current_score}")
current_score += 1
else:
print(f"Sorry, that's wrong, Final score: {current_score}")
end_game = True
elif guess != "A" or guess != "B":
print("invalid entry, type again")
这是应该做的
followers_a = account_a.get("follower_count")
followers_b = account_b.get("follower_count")
end_game = False
while not end_game:
print(f"Compare A: {format_data(account_a)}")
print(vs)
print(f"Against B {format_data(account_b)}")
guess = input("Who has more followers? Type 'A' or 'B': ").upper()
current_score = 0
if guess == "A":
if followers_a > followers_b:
current_score += 1
print(f"You are right! Current score: {current_score}")
followers_b = account_b.get("follower_count")
else:
print(f"Sorry, that's wrong, Final score: {current_score}")
end_game = True
elif guess == "B":
if followers_b > followers_a:
print(f"You are right! Current score: {current_score}")
current_score += 1
followers_a = account_a.get("follower_count")
else:
print(f"Sorry, that's wrong, Final score: {current_score}")
end_game = True
elif guess != "A" or guess != "B":
print("invalid entry, type again")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.