Skip to content

Commit 249b9fb

Browse files
committed
python proggrams
1 parent 39f8c46 commit 249b9fb

File tree

13 files changed

+221
-0
lines changed

13 files changed

+221
-0
lines changed

day1.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
print("this is my first day practice")
2+
3+
x = 1
4+
if x==1:
5+
print("x is 1")
6+
7+
print("Hello Ruchi!")

day10.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#Add "Jake" to the phonebook with the phone number 938273443, and remove Jill from the phonebook.
2+
phonebook = {
3+
"John" : 938477566,
4+
"Jack" : 938377264,
5+
"Jill" : 947662781
6+
}
7+
# your code goes here
8+
phonebook["Jake"] = 938273443
9+
del phonebook["Jill"]
10+
# testing code
11+
if "Jake" in phonebook:
12+
print("Jake is listed in the phonebook.")
13+
14+
if "Jill" not in phonebook:
15+
print("Jill is not listed in the phonebook.")

day11.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#In this exercise, print an alphabetically sorted list of all the functions in the re module containing the word find.
2+
import re
3+
4+
# Your code goes here
5+
find_members = []
6+
7+
for member in dir(re):
8+
if "find" in member:
9+
find_members.append(member)
10+
11+
print(sorted(find_members))

day2.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
mystring="hello"
2+
myfloat=10.0
3+
myint=20
4+
5+
if mystring == "hello":
6+
print(mystring)
7+
if myfloat == 10.0:
8+
print(myfloat)
9+
if myint == 20:
10+
print(myint)

day3.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#In this exercise, you will need to add numbers and strings to the correct lists using the "append" list method. You must add the numbers 1,2, and 3 to the "numbers" list, and the words 'hello' and 'world' to the strings variable.
2+
#You will also have to fill in the variable second_name with the second name in the names list
3+
4+
numbers=[]
5+
numbers.append(1)
6+
numbers.append(2)
7+
numbers.append(3)
8+
strings=[]
9+
10+
names=["John","Eric","Mona"]
11+
second_name=names[1]
12+
13+
strings.append("Hello")
14+
strings.append("World")
15+
16+
print(numbers)
17+
print(strings)
18+
19+
print("Second name in names list is %s" %second_name)

day4.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#You will need to write a format string which prints out the data using the following syntax: Hello John Doe. Your current balance is $53.44.
2+
data = ("John", "Doe", 53.44)
3+
format_string = "Hello %s %s. Your current balance is %s"
4+
5+
print(format_string % data)

day5.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
s = "Strings are awesome!"
2+
# Length should be 20
3+
print("Length of s = %d" % len(s))
4+
5+
# First occurrence of "a" should be at index 8
6+
print("The first occurrence of the letter a = %d" % s.index("a"))
7+
8+
# Number of a's should be 2
9+
print("a occurs %d times" % s.count("a"))
10+
11+
# Slicing the string into bits
12+
print("The first five characters are '%s'" % s[:5]) # Start to 5
13+
print("The next five characters are '%s'" % s[5:10]) # 5 to 10
14+
print("The thirteenth character is '%s'" % s[12]) # Just number 12
15+
print("The characters with odd index are '%s'" %s[1::2]) #(0-based indexing)
16+
print("The last five characters are '%s'" % s[-5:]) # 5th-from-last to end
17+
18+
# Convert everything to uppercase
19+
print("String in uppercase: %s" % s.upper())
20+
21+
# Convert everything to lowercase
22+
print("String in lowercase: %s" % s.lower())
23+
24+
# Check how a string starts
25+
if s.startswith("Str"):
26+
print("String starts with 'Str'. Good!")
27+
28+
# Check how a string ends
29+
if s.endswith("ome!"):
30+
print("String ends with 'ome!'. Good!")
31+
32+
# Split the string into three separate strings,
33+
# each containing only a word
34+
print("Split the words of the string: %s" % s.split(" "))

day6.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Change the variables in the first section, so that each if statement resolves as True.
2+
# change this code
3+
number = 20
4+
second_number = 0
5+
first_array = [1,5,6]
6+
second_array = [1,2]
7+
8+
if number > 15:
9+
print("1")
10+
11+
if first_array:
12+
print("2")
13+
14+
if len(second_array) == 2:
15+
print("3")
16+
17+
if len(first_array) + len(second_array) == 5:
18+
print("4")
19+
20+
if first_array and first_array[0] == 1:
21+
print("5")
22+
23+
if not second_number:
24+
print("6")

day7.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#Loop through and print out all even numbers from the numbers list in the same order they are received. Don't print any numbers that come after 237 in the sequence.
2+
3+
numbers = [
4+
951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
5+
615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
6+
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
7+
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
8+
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, 843, 831, 445, 742, 717,
9+
958, 609, 842, 451, 688, 753, 854, 685, 93, 857, 440, 380, 126, 721, 328, 753, 470,
10+
743, 527
11+
]
12+
13+
for number in numbers:
14+
if number == 237:
15+
break
16+
if number%2==1:
17+
continue
18+
print(number)
19+

day8.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#Add a function named list_benefits() that returns the following list of strings: "More organized code", "More readable code", "Easier code reuse", "Allowing programmers to share and connect code together"
2+
3+
#Add a function named build_sentence(info) which receives a single argument containing a string and returns a sentence starting with the given string and ending with the string " is a benefit of functions!"
4+
5+
def list_benefits():
6+
return["More organized code", "More readable code", "Easier code reuse", "Allowing programmers to share and connect code together"]
7+
8+
def build_sentence(info):
9+
print("%s is a benefit of functions!"%(info))
10+
11+
lst=list_benefits()
12+
build_sentence("This")
13+
print(lst)

day9.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#We have a class defined for vehicles. Create two new vehicles called car1 and car2. Set car1 to be a red convertible worth $60,000.00 with a name of Fer, and car2 to be a blue van named Jump worth $10,000.00.
2+
3+
class vehicle:
4+
name=""
5+
kind="car"
6+
color=""
7+
value=""
8+
9+
def description(self):
10+
desc_str= "%s is %s %s worth $%.2f" %(self.name, self.color, self.kind, self.value)
11+
return desc_str
12+
13+
car1=vehicle()
14+
car1.name="Fer"
15+
car1.color="Red convertible"
16+
car1.value=60000
17+
18+
car2=vehicle()
19+
car2.name="Jump"
20+
car2.color="blue"
21+
car2.value=10000
22+
23+
print(car1.description())
24+
print(car2.description())

guess_number.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import random
2+
3+
num = random.randrange(1,10)
4+
i=1
5+
6+
while i<=3:
7+
inp = int(input("Guess a number between 1 to 10:"))
8+
if num == inp:
9+
print("Yay, congrats You have guessed the correct number")
10+
break
11+
elif (num < inp):
12+
print("Sorry! guess again too High")
13+
elif num > inp:
14+
print("Sorry! guess again too Low")
15+
i = i+1
16+
17+
print(f"The correct number is {num}")

madlibs.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name = input("Name")
2+
adj1 = input("Adjective")
3+
city = input("noun place")
4+
noun1 = input("body part")
5+
vehicle = input("transport")
6+
adj2 = input("Adjective")
7+
noun3 = input("Noun")
8+
adj3 = input("Adjective")
9+
food = input("food")
10+
noun2 = input("Emotion")
11+
adj4 = input("Adjective")
12+
13+
madlib = f"Once upon a time, in a faraway land, there lived a curious traveler named {name}.\
14+
{name} had an insatiable wanderlust and a backpack filled with {adj1} essentials.\
15+
One sunny morning, {name} decided to embark on a(n) {adj1} adventure to {city}. \
16+
With a map in {noun1} and a heart full of excitement, {name} set off on a(n) {vehicle}, ready to explore the {adj2} landscapes and {noun3} of this mysterious place. \
17+
Along the way, {name} encountered friendly locals who shared their {adj3} traditions and {food}. \
18+
As the journey continued, {name} couldn't help but feel {noun2} by the beauty of the world and the kindness of strangers. This travel adventure was a true {adj4} experience that {name} would cherish forever, \
19+
reminding them that the world is a vast and wonderful place waiting to be explored."
20+
21+
22+
print(madlib)
23+

0 commit comments

Comments
 (0)