Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #CS 171 by Shreedev Patel
- #Section 068
- import sys
- planets=['Moon','Earth','Pluto','Neptune','Uranus','Saturn','Jupiter','Mars','Venus','Mercury','Sun']
- gravity=[-1.622,-9.81,-0.42,-14.07,-10.67,-11.08,-25.95,-3.77,-8.87,-3.59,-274.13]
- fuelAmount= [150,5000,1000,1000,1000,1000,1000,1000,1000,1000,50000]
- def ask_fuel(current_fuel):
- while True:
- try:
- f= input('Enter units of fuel to use:\n')
- f= int(f)
- if f<0:
- print('Cannot use negative fuel.')
- if current_fuel < f:
- print('Not enough fuel. Max fuel')
- else:
- break
- except:
- print("Not a valid input.")
- return f
- def play_level(names,gravity,fuel):
- G = gravity
- A = 50
- V = 0
- current_fuel = fuel
- s = 0
- T = 0.10
- print('Landing on the',names)
- print('Gravity is',G,'m/s^2')
- print('Initial Altitude',round(A,2),'meters')
- print('Initial Velocity',round(V,2),'m/s')
- print('Burning a unit of fuel causes 0.10m/s slowdown')
- print('Initial Fuel Level:',round(current_fuel,2),'units')
- print('\n')
- print('GO')
- while A>0:
- f = ask_fuel(current_fuel)
- current_fuel = current_fuel - f
- V=V+G+T*f
- A=A+V
- s=s+1
- if(A<0):
- A=0
- print('After',s,'seconds, altitude is',round(A,2),'meters, velocity is',round(V,2),'m/s.')
- if(current_fuel>-1):
- print('Remaining Fuel:',current_fuel)
- if -2<V<2:
- print('Landed')
- return True
- else:
- print('Crashed')
- return False
- def game():
- for i in range(0,11):
- lev=input('Do you want to play level '+str(i+1)+'?')
- if not lev=='yes' and not lev =='Yes':
- sys.exit()
- print('Entering Level', i+1)
- a = play_level(planets[i], gravity[i],fuelAmount[i])
- if a == False:
- i -= 1
- input1 = input('Do you wanna play level {} again'.format(i+1))
- if input1 == 'yes':
- a = play_level(planets[i], gravity[i],fuelAmount[i])
- if input1 == 'no':
- break
- return
- print('Welcome to Lunar Lander Game.')
- game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement