我是python的新手,我想知道如何使代码重复该random.randint部分100次。
#head's or tail's
print("you filp a coin it lands on...")
import random
heads = 0
tails = 0
head_tail =random.randint(1, 2,)
if head_tail == 1:
print("\nThe coin landed on heads")
else:
print("\nThe coin landed on tails")
if head_tail == 1:
heads += 1
else:
tails += 1
flip = 0
while True :
flip +=1
if flip > 100:
break
print("""\nThe coin has been fliped 100 times
it landed on heads""", heads, """times and tails""", tails,
"""times""") …Run Code Online (Sandbox Code Playgroud) 有没有办法让这段代码更短?
price1 = input("\nEnter price here: ")
price1 = int(price1)
price2 = input("\nEnter price here: ")
price2 = int(price2)
price3 = input("\nEnter price here: ")
price3 = int(price3)
price4 = input("\nEnter price here: ")
price4 = int(price4)
price5 = input("\nEnter price here: ")
price5 = int(price5)
price6 = input("\nEnter price here: ")
price6 = int(price6)
price7 = input("\nEnter price here: ")
price7 = int(price7)
price8 = input("\nEnter price here: ")
price8 = int(price8)
price9 = input("\nEnter price here: ")
price9 …Run Code Online (Sandbox Code Playgroud) python ×2