Use what you've learnt so far to construct an app that can work for everyone.
The idea here is to collect a person's name, age, and interests, store them in a variable, then print them in the end.
Starting point
| print("Hello world") |
| my_name = "Mr. Brother Man" | |
| my_age = 42 | |
| my_interests = ["Anime", "Archery", "Skating"] | |
| print("My name is", my_name, "and I am", my_age, "and my interests are", *my_interests) | |
| # alternate way | |
| # message = f"My name is {my_name} and I am {my_age} and my interests are {my_interests[0]}, {my_interests[1]}, and {my_interests[2]}" | |
| # print(message) | |
| # my_name is a string. It is used for things like names, and natural language | |
| # my_age is an integer. It is used for whole numbers, both negative and positive | |
| # my_interests is a list. It is used for grouping/ordering related variables |
| input("What is your name: ") | |
| name = input("What is your name: ") | |
| print(name) |
| name = input("What is your name: ") | |
| age = input("What") | |
| interest1 = input("What is your number 1 interest: ") | |
| interest2 = input("What is ") | |
| interest3 = input("What ") | |
| combined = f"Your name is {name} and" | |
| print(combined) |
Notice how you needed to define interest1, interest2, and interest3 manually? What if there was a way to write less code? That is where a for-loop comes in.
| name = input("What is your name: ") | |
| age = input("What is your age: ") | |
| interests = [] | |
| for i in range(3): | |
| interest = input(f"What is your number {i} interest: ") | |
| interests.append(interest) | |
| interests_string = ", ".join(interests) | |
| combined = f"Your name is {name} and you are {age} years old with interests in {interests_string}" | |
| print(combined) |