Skip to content

Commit 5ea0564

Browse files
authored
Add files via upload
1 parent f231396 commit 5ea0564

File tree

92 files changed

+1637
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+1637
-0
lines changed

Problem Set 0/einstein/einstein.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#A program in Python that prompts the user for mass as an integer (in kilograms) and then outputs the equivalent number of Joules as an integer.
2+
3+
4+
m=int(input("Enter mass in kilograms: "))
5+
c=300000000
6+
print(f"Energy E:{m*c*c}")

Problem Set 0/faces/faces.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
2+
3+
def convert(prompt):
4+
happy=":)"
5+
sad=":("
6+
prompt=prompt.replace(":)","🙂")
7+
prompt=prompt.replace(":(","🙁")
8+
9+
return (prompt)
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
def main():
53+
userinput=input()
54+
print(convert(userinput))
55+
56+
57+
58+
59+
main()

Problem Set 0/indoor/indoor.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#A program that prompts the user for input and then outputs that same input in lowercase.
2+
3+
user_input=input().lower()
4+
print(user_input)

Problem Set 0/playback/playback.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#A program that prompts the user for input and then outputs that same input, replacing each space with '...'.
2+
3+
user_input=input()
4+
user_input=user_input.replace(' ','...')
5+
print(user_input)

Problem Set 0/tip/tip.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def main():
2+
dollars = dollars_to_float(input("How much was the meal? "))
3+
percent = percent_to_float(input("What percentage would you like to tip? "))
4+
tip = dollars * percent
5+
print(f"Leave ${tip:.2f}")
6+
7+
8+
def dollars_to_float(d):
9+
# TODO
10+
d=float(d.replace('$',''))
11+
return (d)
12+
13+
14+
def percent_to_float(p):
15+
# TODO
16+
p=float(p.replace('%',''))
17+
p=p/100
18+
return (p)
19+
20+
21+
22+
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def emoji_converter(message):
2+
words = message.split( " ")
3+
emojis = {
4+
":)" : "😀",
5+
":(" : "😞",
6+
"lol" : "😂",
7+
"sick":"😨",
8+
"happy": "😀",
9+
"mermaid": "🧜‍"
10+
}
11+
outcome = " "
12+
for word in words:
13+
outcome += emojis.get(word, word) + " "
14+
return output
15+
16+
17+
Message = input (“>”)
18+
print(emoji_converter(message))

Problem set 1/bank/bank.py.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
userip=input("Greeting: ")
2+
if(userip.lower().strip()== 'hello'or userip.strip().lower().startswith('hello')):
3+
print('$0')
4+
elif(userip.strip().lower().startswith('h')):
5+
print('$20')
6+
else:
7+
print("$100")

Problem set 1/bank/bnk1.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
userip=input("Greeting: ")
2+
if(userip.strip().lower()== 'hello'or userip.strip().lower().startswith('hello')):
3+
print('$0')
4+
elif(userip.strip().lower().startswith('h')):
5+
print('$20')
6+
else:
7+
print("$100")

Problem set 1/deep/deep.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
userip=input("What is the Answer to the Great Question of Life, the Universe, and Everything?")
2+
if (userip.strip() == '42' or userip.lower().strip() == "forty two" or userip.lower().strip() == "forty-two"):
3+
print('Yes')
4+
else:
5+
print('No')
6+
7+
"""
8+
txt.strip() -to remove spaces before and after the word.
9+
txt.lower() -to make all letters lower case.
10+
11+
"""
12+

Problem set 1/extensions/extension.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
userip=input("File name: ")
2+
if(userip.lower().endswith('.gif')):
3+
print('image/gif')
4+
elif(userip.lower().endswith('.jpg') or userip.lower().endswith('.jpeg') ):
5+
print('image/jpeg')
6+
elif(userip.lower().endswith('.png')):
7+
print('image/png')
8+
elif(userip.lower().endswith('.pdf')):
9+
print('application/pdf')
10+
elif(userip.lower().endswith('.txt')):
11+
print('text/plain')
12+
elif(userip.lower().endswith('.zip')):
13+
print('application/zip')
14+
else:
15+
print('application/octet-stream')
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
userip=input('Expression: ')
2+
x,y,z=userip.split(" ")
3+
x=int(x)
4+
z=int(z)
5+
match y:
6+
case '+':
7+
print("{0:d}.0".format(x+z))
8+
case '-':
9+
print("{0:d}.0".format(x-z))
10+
case '*':
11+
print("{0:d}.0".format(x*z))
12+
case '/':
13+
print("{0:.1f}".format(x/z))
14+
15+
16+
17+
18+

Problem set 1/meal/meal.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
def main():
2+
time=input("What time is it?")
3+
time=convert(time)
4+
if (7.0<=time<=8.0):
5+
print("Breakfast time")
6+
elif (12.0<=time<=13.0):
7+
print("Lunch time")
8+
elif (18.0<=time<=19.0):
9+
print("Dinner time")
10+
11+
def convert(time):
12+
hour,minute=time.split(":")
13+
minute=float(minute)/60
14+
return(float(hour)+minute)
15+
16+
if __name__ == "__main__":
17+
18+
main()

Problem_Set4/adieu/adieu.py

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import inflect
2+
p=inflect.engine()
3+
names=[]
4+
while True:
5+
try:
6+
print("Name:",end='')
7+
name=input("")
8+
names.append(name)
9+
except EOFError:
10+
break
11+
print(f"Adieu,adieu,to {p.join(names)}")

Problem_Set4/bitcoin/bitcoin.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import sys
2+
import requests
3+
import json
4+
5+
#Check for command line,if it doesnt exist,exit with appropriate message.
6+
if len(sys.argv)<2:
7+
sys.exit("Missing command-line argument")
8+
9+
#Store argument in var.
10+
userip=sys.argv[1]
11+
12+
#Check if argument is float type.
13+
if(float(userip)):
14+
try:
15+
#Get response for API.
16+
response=requests.get("https://api.coindesk.com/v1/bpi/currentprice.json")
17+
18+
#Store formatted response in var.
19+
store=response.json()
20+
21+
#Store dict corresponding to key-"bpi" in dict_store in another a var.
22+
dict_bpi=store["bpi"]
23+
24+
#Store dict corresponding to key-"USD" in dict_bpi, in another a var.
25+
dict_USD=dict_bpi["USD"]
26+
27+
#Iterate over dict_USD.
28+
for keys in dict_USD:
29+
30+
#If key==rate_float,store its corresponding value in a var.
31+
if keys=="rate_float":
32+
rate_float=(dict_USD[keys])
33+
34+
#Find amount and print it.
35+
amount=float(userip)*rate_float
36+
print(f"${amount:,.4f}")
37+
38+
#Check for ambiguous exception and exit with appropriate message.
39+
except requests.RequestException:
40+
sys.exit("There was an ambiguous exception that occurred while handling your request")
41+
42+
#Exit if cmd arg is not a num with appropriate message.
43+
else:
44+
sys.exit("Command-line argument is not a number")

Problem_Set4/emojize/emojize.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#import emoji module.
2+
import emoji
3+
#Get user input.
4+
userip=input("Input: ")
5+
#Print emoiji returned by emojize function.
6+
print(emoji.emojize(f'Output: {userip}',language='alias'))

Problem_Set4/figlet/figlet.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#Import neccessary modules.
2+
import sys
3+
import random
4+
from pyfiglet import Figlet
5+
figlet = Figlet()
6+
7+
#Get command line argument.
8+
userip=sys.argv[1:]
9+
10+
#If len of argument is>2 then exit.
11+
if len(userip)>2:
12+
sys.exit("Invalid usage")
13+
14+
#Check if length of argument is 0.
15+
elif len(userip)==0:
16+
17+
#If length is 0,Get user input and print it in random format.
18+
name=input("Input: ")
19+
20+
#Setting random font from list of of font using choice function.
21+
figlet.setFont(font=random.choice(figlet.getFonts()))
22+
print(figlet.renderText(name))
23+
24+
#Check if first string is '-f' or '--f'.
25+
elif (userip[0]=='-f' or userip[0]=='--f'):
26+
27+
#Check if second string is in list of fonts and print it in demanded format.
28+
if userip[1] in figlet.getFonts():
29+
name=input("Input: ")
30+
figlet.setFont(font=userip[1])
31+
print(figlet.renderText(name))
32+
33+
#If none of above condition is satisfied then exit.
34+
else:
35+
sys.exit("Invalid usage")
36+
else:
37+
sys.exit("Invalid usage")
38+
39+
40+
41+
42+
43+
44+
45+

Problem_Set4/game/game.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import random
2+
#Start outer loop.
3+
while True:
4+
#Set flag to stop outer loop.
5+
flag=0
6+
7+
try:
8+
#Get level from user.
9+
lvl=int(input("Level: "))
10+
11+
#Raise exception if level<1.
12+
if(lvl<1):
13+
raise ValueError
14+
15+
#Generate random num between 1 and level.
16+
rand=random.randint(1,lvl)
17+
18+
#Start inner loop.
19+
while True:
20+
21+
try:
22+
#Get geuss from user.
23+
guess=int(input("Guess: "))
24+
25+
#Raise exception if guess<1.
26+
if(guess<1):
27+
raise ValueError
28+
29+
#If guess=random num set flag to 1(to kill outer loop) and break out of inner loop.
30+
if(guess==rand):
31+
print("Just right!")
32+
flag=1
33+
break
34+
35+
#Reprompt if guess<random num, after neccessary o/p message.
36+
elif(guess<rand):
37+
print("Too small!")
38+
39+
#Reporompt if guess>random num,after neccessary o/p message.
40+
elif(guess>rand):
41+
print("Too large!")
42+
except:pass
43+
44+
#Kills outer loop.
45+
if(flag==1):break
46+
except:
47+
pass

0 commit comments

Comments
 (0)