Skip to content

Commit 4b36e24

Browse files
authored
String, dicts
1 parent cbda4b2 commit 4b36e24

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

PracPy string.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# # Implement a function that takes as input three variables, and returns the largest of the three. Do this without using the Python max() function!
5+
#
6+
#
7+
8+
# In[1]:
9+
10+
11+
def l3():
12+
a=int(input("Enter 1st:"))
13+
b=int(input("Enter 2nd:"))
14+
c=int(input("Enter 3rd:"))
15+
if a>b and a>c:
16+
return a
17+
elif b>a and b>c:
18+
return b
19+
else:
20+
return c
21+
22+
print(l3())
23+
24+
25+
# # Write a program that takes a list of numbers (for example, a = [5, 10, 15, 20, 25]) and makes a new list of only the first and last elements of the given list. For practice, write this code inside a function
26+
27+
# In[2]:
28+
29+
30+
a = [5, 10, 15, 20, 25]
31+
32+
def listend(x):
33+
return [x[0], x[-1]]
34+
35+
print(listend(a))
36+
37+
38+
# # Create a dictionary (in your file) of names and birthdays. When you run your program it should ask the user to enter a name, and return the birthday of that person back to them
39+
40+
# In[4]:
41+
42+
43+
birthdays={"dad":'9/4/1957',
44+
"mom": '8/7/1960',
45+
"bro": '17/9/1989',
46+
"self": '26/1/1994'}
47+
48+
print('Welcome to the birthday dictionary. We know the birthdays of:')
49+
for name in birthdays:
50+
print(name)
51+
52+
print('Who\'s birthday do you want to look up?')
53+
name = input()
54+
if name in birthdays:
55+
print('{}\'s birthday is {}.'.format(name, birthdays[name]))
56+
else:
57+
print('Sadly, we don\'t have {}\'s birthday.'.format(name))
58+
59+
60+
# In[ ]:
61+
62+
63+
64+

0 commit comments

Comments
 (0)