[英]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.