Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. #CS 171 by Shreedev Patel
  2. #Section 068
  3.  
  4. import sys
  5.  
  6. planets=['Moon','Earth','Pluto','Neptune','Uranus','Saturn','Jupiter','Mars','Venus','Mercury','Sun']
  7. gravity=[-1.622,-9.81,-0.42,-14.07,-10.67,-11.08,-25.95,-3.77,-8.87,-3.59,-274.13]
  8. fuelAmount= [150,5000,1000,1000,1000,1000,1000,1000,1000,1000,50000]
  9.  
  10. def ask_fuel(current_fuel):
  11. while True:
  12. try:
  13. f= input('Enter units of fuel to use:\n')
  14. f= int(f)
  15. if f<0:
  16. print('Cannot use negative fuel.')
  17. if current_fuel < f:
  18. print('Not enough fuel. Max fuel')
  19. else:
  20. break
  21. except:
  22. print("Not a valid input.")
  23. return f
  24.  
  25. def play_level(names,gravity,fuel):
  26. G = gravity
  27. A = 50
  28. V = 0
  29. current_fuel = fuel
  30. s = 0
  31. T = 0.10
  32. print('Landing on the',names)
  33. print('Gravity is',G,'m/s^2')
  34. print('Initial Altitude',round(A,2),'meters')
  35. print('Initial Velocity',round(V,2),'m/s')
  36. print('Burning a unit of fuel causes 0.10m/s slowdown')
  37. print('Initial Fuel Level:',round(current_fuel,2),'units')
  38. print('\n')
  39. print('GO')
  40. while A>0:
  41. f = ask_fuel(current_fuel)
  42. current_fuel = current_fuel - f
  43. V=V+G+T*f
  44. A=A+V
  45. s=s+1
  46. if(A<0):
  47. A=0
  48. print('After',s,'seconds, altitude is',round(A,2),'meters, velocity is',round(V,2),'m/s.')
  49. if(current_fuel>-1):
  50. print('Remaining Fuel:',current_fuel)
  51. if -2<V<2:
  52. print('Landed')
  53. return True
  54. else:
  55. print('Crashed')
  56. return False
  57. def game():
  58. for i in range(0,11):
  59. lev=input('Do you want to play level '+str(i+1)+'?')
  60. if not lev=='yes' and not lev =='Yes':
  61. sys.exit()
  62. print('Entering Level', i+1)
  63. a = play_level(planets[i], gravity[i],fuelAmount[i])
  64. if a == False:
  65. i -= 1
  66. input1 = input('Do you wanna play level {} again'.format(i+1))
  67. if input1 == 'yes':
  68. a = play_level(planets[i], gravity[i],fuelAmount[i])
  69. if input1 == 'no':
  70. break
  71.  
  72.  
  73.  
  74.  
  75.  
  76. return
  77.  
  78. print('Welcome to Lunar Lander Game.')
  79.  
  80. game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement