这个对于你们堆栈溢出来说是基本的。我正在尝试运行以下代码,但无论我得到的放置变量点总是0:
import random
number_disks = random.randint( 1, 5 )
user_input = ( "Congratulations you have " + str(number_disks) + "disks to
play with." )
disk_count = 1
hit_count = 0
placement = 0
points = 0
while disk_count <= number_disks:
print("Droppping disk " + str( disk_count ) + "..." )
while hit_count != 5:
hit_direction = random.randint( 0, 1 )
if hit_direction == 0:
print( "-Tick-" )
placement = placement + 1
elif hit_direction == 1:
print( "-Tock-" )
placement = placement - 1
hit_count = hit_count + 1
if placement == 5 or -5 or -1 or 1:
points = 0
elif placement == 4 or -4:
points = 100
elif placement == 3 or -3:
points = 500
elif placement == 2 or -2:
points = 1000
elif placement == 0:
points = 10000
print( str( placement ) )
print( str( points ) )
print( "The disk landed in $" + str( points ) + ", Congratulations!" )
disk_count = disk_count + 1
hit_count = 0
placement = 0