Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ex1.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,4 @@
#
# return 0;
# }
week = input("Enter week number: ")
7 changes: 7 additions & 0 deletions src/ex2.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,10 @@
#
# return 0;
# }

week = ["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]
while True:
week_input = int(input("inserire giorno: "))
if week_input>=0 and week_input<=7:
break
Comment on lines +54 to +57

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosa succede se l'utente inserisce 7?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah si, devo togliere l'uguale in "week_input<=7" sennò accedo a memoria all'esterno dell'array

print("hai selezionato: ", week[week_input])
68 changes: 39 additions & 29 deletions src/ex3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,47 @@
# {
# string textInput;
#
# cout << "Enter a famous name+surname, ex. BarackObama " << endl;
# cout << "Enter a famous name+surname, ex. BarackObama ")
# cin >> textInput;
#
# if (textInput == "BarackObama")
# {
# cout << "44th president of the United States" << endl;
# }
# else if (textInput == "SandroPertini")
# {
# cout << "Former President of the Italian Republic" << endl;
# }
# else if (textInput == "NelsonMandela")
# {
# cout << "Former President of South Africa" << endl;
# }
# else if (textInput == "MahatmaGandhi")
# {
# cout << "Bapu" << endl;
# }
# else if (textInput == "DonaldKnuth")
# {
# cout << "Creator of LaTeX" << endl;
# }
# else if (textInput == "DennisRitchie")
# {
# cout << "Creator of C" << endl;
# }
# else
# {
# cout << "Invalid input! Please enter a good name!" << endl;
# }
#
# # print(44th president of the United States")
# # if (textInput == "SandroPertini")
# # print(Former President of the Italian Republic")
# # if (textInput == "NelsonMandela")
# # print(Former President of South Africa")
# # if (textInput == "MahatmaGandhi")
# # print(Bapu")
# # if (textInput == "DonaldKnuth")
# # print(Creator of LaTeX")
# # if (textInput == "DennisRitchie")
# # print(Creator of C")
# # else
# # print(Invalid input! Please enter a good name!")
# #
# return 0;
# }

good = False
textInput = input("Enter a famous name+surname, ex. BarackObama ")
if textInput == "BarackObama":
print("44th president of the United States")
good = True
if textInput == "SandroPertini":
print("Former President of the Italian Republic")
good = True
if textInput == "NelsonMandela":
print("Former President of South Africa")
good = True
if textInput == "MahatmaGandhi":
print("Bapu")
good = True
if textInput == "DonaldKnuth":
print("Creator of LaTeX")
good = True
if textInput == "DennisRitchie":
print("Creator of C")
good = True

if good == False:
print("Invalid input! Please enter a good name!")
Comment on lines +31 to +53

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invece che usare una variabile ausiliaria potresti semplicemente concatenare degli elif e far ricadere la casistica non valida nell'else finale

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

si, in effetti non ci ho pensato