Skip to content

Commit ec2c218

Browse files
committed
day 7 | strings manipulation
1 parent 539f819 commit ec2c218

3 files changed

+150
-0
lines changed

35_Challenge-ToDoList.py

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import os, time
2+
myList = []
3+
4+
print("ToDo List Manager")
5+
6+
def showMenu():
7+
print("What do you want to do?\n1. View\n2. Add\n3. Remove\n4. Edit")
8+
option = int(input("> "))
9+
return option
10+
11+
def clearConsole(sec):
12+
time.sleep(sec)
13+
os.system("clear")
14+
15+
def showList():
16+
print()
17+
count = 1
18+
for item in myList:
19+
print(f"{count}: {item}")
20+
count += 1
21+
print()
22+
23+
def add():
24+
item = input("What do you want to add? ")
25+
if item in myList:
26+
print()
27+
print("This item already exist!")
28+
else:
29+
print()
30+
myList.append(item)
31+
print("Item added")
32+
33+
def remove():
34+
item = input("What do you want to remove? ")
35+
if item in myList:
36+
print()
37+
choice = input(f"Are you sure you want to remove {item}? ")
38+
if choice == "yes" or choice == "Yes":
39+
myList.remove(item)
40+
print()
41+
print("Item removed")
42+
elif item == "everything" or item == "Everything":
43+
myList.clear()
44+
print()
45+
print("ToDo erased")
46+
else:
47+
print()
48+
print(f"{item} doesn´t exist")
49+
50+
def edit():
51+
item = input("What do you want to edit? ")
52+
if item in myList:
53+
print()
54+
newItem = input("What do you want to change to it? ")
55+
print()
56+
choice = input(f"Are you sure you want to edit {item}? ")
57+
if choice == "yes" or choice == "Yes":
58+
print()
59+
myList[myList.index(item)] = newItem
60+
print("Item edited")
61+
else:
62+
print()
63+
print("Operation canceled")
64+
65+
66+
while True:
67+
clearConsole(1)
68+
choice = showMenu()
69+
70+
if choice == 1:
71+
clearConsole(0.5)
72+
showList()
73+
clearConsole(5)
74+
elif choice == 2:
75+
clearConsole(0.5)
76+
add()
77+
elif choice == 3:
78+
clearConsole(0.5)
79+
remove()
80+
elif choice == 4:
81+
clearConsole(0.5)
82+
edit()
83+
else:
84+
print("I don´t get it. Bye")
85+
break
86+

36_stringManipulation.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Day 36 on Replit: "String Manipulation"
2+
3+
# Fix my code section
4+
5+
# whatToEat = input("What do you fancy for dinner? ")
6+
# if whatToEat.strip = "pasta":
7+
# print("Get out the pasta maker.")
8+
# elif whatToEatlower() == "TACOS":
9+
# print("Let's do Taco Tuesday!")
10+
# else:
11+
# print("Go search the fridge.")
12+
13+
whatToEat = input("What do you fancy for dinner? ")
14+
if whatToEat.strip().lower() == "pasta":
15+
print("Get out the pasta maker.")
16+
elif whatToEat.strip().lower() == "tacos":
17+
print("Let's do Taco Tuesday!")
18+
else:
19+
print("Go search the fridge.")
20+
21+
22+
# Challenge section
23+
names = []
24+
25+
def show():
26+
print()
27+
for i in names:
28+
print(i)
29+
print()
30+
31+
while True:
32+
name = input("First name: ").strip().capitalize()
33+
surname = input("Last name: ").strip().capitalize()
34+
fullname = name + " " + surname
35+
36+
if fullname not in names:
37+
names.append(fullname)
38+
else:
39+
print("Error: Duplicate name!")
40+
41+
show()
42+

37_stringSlicing.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Day 37 on Replit: "String Slicing"
2+
3+
# Fix my code section
4+
5+
# This code should output 'Hello there'
6+
# myString = "Hello there my friend."
7+
# print(myString[0:10:0])
8+
9+
# This code should output 'Hello there'
10+
myString = "Hello there my friend."
11+
print(myString[0:11:1])
12+
13+
# Challenge section
14+
15+
print("STAR WARS NAME GENERATOR")
16+
17+
firstName = input("Enter your first name: ").strip()
18+
secondName = input("Enter your second name: ").strip()
19+
mumName = input("Enter your Mum´s first name: ").strip()
20+
cityName = input("Enter the city where you were born: ").strip()
21+
22+
print(f"{firstName[:3].capitalize()}{secondName[:3]} {mumName[:2].capitalize()}{cityName[-3:]}")

0 commit comments

Comments
 (0)