У меня есть школьный проект, над которым я работал, но я не могу работать. Я пробовал перемещаться по while True
, но я либо получаю бесконечный цикл, либо доходит до последнего ввода и только возвращается к началу.Бесконечная петля и не получая ожидаемых результатов
import random
while True:
dice1=random.randint (0,7)
dice2=random.randint (0,7)
break
strengthone = int(input ("Player 1, between 1 and 10 What do you want your characters strength to be? Higher is not always better."))
skillone = int(input ("Player 1, between 1 and 10 What do you want your characters skill to be? Higher is not always better."))
while True:
if strengthone > 10:
print ("Incorrect value")
else:
print ("Good choice.")
if skillone > 10:
print ("Incorrect value.")
else:
print ("Good choice.")
strengthtwo = int(input ("Player 2, between 1 and 10 what do you want your characters strength to be? Higher is not always better."))
skilltwo = int(input ("Player 2, between 1 and 10 what do you want your characters skill to be? Higher is not always better."))
if strengthtwo > 10:
print ("Incorrect value.")
else:
print ("Good choice.")
if skillone > 10:
print ("Incorrect value.")
else:
print ("Good choice.")
while True:
strengthmod = strengthone - strengthtwo
skillmod = skillone - skilltwo
strengthmodone = strengthone - strengthtwo
skillmodone = skillone - skilltwo
strengthmodtwo = strengthone - strengthtwo
skillmodtwo = skillone - skilltwo
print ("Player 1, you rolled a", str(dice1))
print ("Player 2, you rolled a", str(dice2))
if dice1 == dice2:
print ("")
elif dice1 > dice2:
strengthmodone = strengthmod + strengthone
strengthmodone = strengthmod + strengthone
elif dice2 > dice1:
strengthmodtwo = strengthmod + strengthtwo
skillmodtwo = skillmod + skilltwo
elif dice1 < dice2:
strengthmodone = strengthmod - strengthone
skillmodone= skillmod - skillone
else:
dice2 < dice1
strengthmodtwo = strengthmod - strengthtwo
skillmodtwo = skillmod - skilltwo
while True:
strengthmodone = strengthmodone - dice1
strengthmodtwo = strengthmodtwo - dice2
break
while True:
if strengthmodone == 0:
print ("Player one dies, well done player two. You win!")
elif strengthmodtwo == 0:
print ("Player two dies, well done player one. You win!")
elif strengthmodone > 0:
strengthmodone - 1
else:
strengthmodtwo == 0
strengthmodtwo - 1
break
break
Любая помощь очень ценится :)
Я бы не рекомендовал использовать 'while True', если вам не нужно - знаете ли вы, что он делает? –
Определите проблему конкретно. Что случилось? Где вы думаете, что все идет не так? Что ожидается? etc –
Я не думаю, что вы понимаете, для чего используется цикл while. Возможно, вам стоит вернуться к основам и узнать, как они работают и когда их следует использовать. – Tim