#APF221-Independence №1 #Group: 1-407 #Name: Misheel Munkhjargal #This code is written by Visual Studio Code, and the color code does nor work in programs such as Jupyter and Spyder. import random class color: BOLD='\033[1m' CYAN='\033[96m' RED='\033[91m' GREEN='\033[92m' DARKCYAN='\033[36m' END='\033[0m' km_traveled=0 thirst=0 camel_tired=0 oasis=0 police_traveled=-20 drink=5 print("Welcome to Escape game") print("You are escaping from a prison in the middle of a sand dune, and to escape, you will steal your warden's camel.") print("Of course the police will chase you and you will be saved if you can reach your hideout 200km away.") print("Bonus: You have a 1-use trap that you can use to distract the police.") print("But be aware that the trap may fail.") print("Your escape will depend on the decisions you make.") print("Good luck, and have a fun") done=False while not done: print("A. Drink water.") print("B. Go middle speed.") print("C. Go full your speed.") print("D. Stop and rest.") print("E. Check the situation.") print("F. Use a trap.") print("Q. Quit.\n") choice=input("Your choice? :") print("") if choice=="q": done=True elif choice=="f": oasis=random.randrange(1, 5) if oasis==3: police_down=random.randrange(3, 10) police_traveled=police_traveled-police_down print(color.CYAN+"The police got the trap, ", police_down, "by spending kilometers on trap, you have a chance to escape.\n"+color.END) else: print(color.RED+"The trap failed, so the police continue to chase you.\n"+color.END) elif choice=="e": print(color.BOLD+"The road traveled: ", km_traveled, "km"+color.END) print(color.BOLD+"Amount of water in the container: ", drink, "litres"+color.END) print(color.BOLD+"Police from you", km_traveled-police_traveled, "km away."+color.END) print(color.BOLD+"Tired level of camel: ", camel_tired, "%"+color.END) print(color.BOLD+"Thirsty level: ", thirst, "\n"+color.END) elif choice=="d": camel_tired=0 police_up=random.randrange(10, 15) police_traveled=police_traveled+police_up print(color.BOLD+"The camel rested! But the police ",police_up, " traveled km.\n"+color.END) elif choice=="c": if camel_tired>=50: full_speed=random.randrange(5, 10) else: full_speed=random.randrange(10, 20) km_traveled=km_traveled+full_speed police_up=random.randrange(10, 15) police_traveled=police_traveled+police_up thirst=thirst+1 camel_tired=camel_tired+random.randrange(2,3)*10 oasis=random.randrange(1, 10) if oasis==5: thirst=0 camel_tired=0 drink=5 print(color.CYAN+"You traveled", full_speed, "km."+color.END) print(color.CYAN+"Congratulations on meeting Oasis!."+color.END) print(color.CYAN+"Your mouth's thirst is quenched and your bottles are filled with water"+color.END) print(color.CYAN+"And your camel rested."+color.END) print(color.CYAN+"But, police ", police_up, " traveled km.\n"+color.END) print() else: print(color.BOLD+"You traveled ", full_speed, "km."+color.END) print(color.BOLD+"Tired level of camel: ", camel_tired, "%"+color.END) print(color.BOLD+"Thirsty level: ", thirst,"" +color.END) print(color.BOLD+"Police traveled ", police_up, "km\n"+color.END) elif choice=="b": if camel_tired>=50: mid_speed=random.randrange(3, 8) mid_speed=random.randrange(5, 12) km_traveled=km_traveled+mid_speed police_up=random.randrange(10, 15) police_traveled=police_traveled+police_up thirst=thirst+1 camel_tired=camel_tired+random.randrange(1,2)*10 oasis=random.randrange(1, 10) if oasis==5: thirst=0 camel_tired=0 drink=5 print(color.CYAN+"You traveled", mid_speed, "km."+color.END) print(color.CYAN+"Congratulations on meeting Oasis!."+color.END) print(color.CYAN+"Your mouth's thirst is quenched and your bottles are filled with water"+color.END) print(color.CYAN+"And your camel rested."+color.END) print(color.CYAN+"But, police traveled ", police_up, "km\n"+color.END) print() else: print(color.BOLD+"You traveled ", mid_speed, "km."+color.END) print(color.BOLD+"Tired level of camel: ", camel_tired, "%"+color.END) print(color.BOLD+"Thirsty level: ", thirst,""+color.END) print(color.BOLD+"Police traveled ", police_up, "km\n"+color.END) elif choice=="a": if drink>0: print(color.BOLD+"You quenched your thirst and drank 1 bottle of water."+color.END) drink=drink-1 print(color.BOLD+"You have ", drink, "bottles of water.\n"+color.END) thirst=0 else: print(color.RED+"The bottle of water finished!!!\n"+color.END) else: print(color.BOLD+"Please enter only the letters in the options!\n"+color.END) if km_traveled>=200: print(color.GREEN+"Congralutions! You did it, managed to escape from the police by successfully crossing the sand dunes.\n"+color.END) done=True break if thirst>=5: print(color.RED+"You dead because of thirst, you moron.!"+color.END) done=True break elif thirst>=4: print(color.RED+"Dying of thirst, you dummy.!\n"+color.END) elif thirst>=3: print(color.RED+"I'm thirsty, TT.!\n"+color.END) if camel_tired>=100: print(color.RED+"Your camel dead because of tired, you fool.!"+color.END) done=True break elif camel_tired>=50: print(color.RED+"Your camel is tired.!\n"+color.END) if km_traveled-police_traveled<=0: print(color.RED+"You arrested by police!!!!!."+color.END) done=True break elif km_traveled-police_traveled<=15: print(color.RED+"The police are approaching.\n"+color.END) print(color.BOLD+"!!!GAME OVER.!!!"+color.END)
Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.
OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.
import sys
name = sys.stdin.readline()
print("Hello "+ name)
Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.
When ever you want to perform a set of operations based on a condition IF-ELSE is used.
if conditional-expression
#code
elif conditional-expression
#code
else:
#code
Indentation is very important in Python, make sure the indentation is followed correctly
For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.
mylist=("Iphone","Pixel","Samsung")
for i in mylist:
print(i)
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while condition
#code
There are four types of collections in Python.
List is a collection which is ordered and can be changed. Lists are specified in square brackets.
mylist=["iPhone","Pixel","Samsung"]
print(mylist)
Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
Below throws an error if you assign another value to tuple again.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)
Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.
myset = {"iPhone","Pixel","Samsung"}
print(myset)
Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.
mydict = {
"brand" :"iPhone",
"model": "iPhone 11"
}
print(mydict)
Following are the libraries supported by OneCompiler's Python compiler
Name | Description |
---|---|
NumPy | NumPy python library helps users to work on arrays with ease |
SciPy | SciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation |
SKLearn/Scikit-learn | Scikit-learn or Scikit-learn is the most useful library for machine learning in Python |
Pandas | Pandas is the most efficient Python library for data manipulation and analysis |
DOcplex | DOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling |