Easy Python Challenges

1st Challenge

Make a program to take a user's name, age, and favorite programming language, and print them back.

name = input("What is your name: ")
age = input("How old are you: ")
fav = input("What is your favorite programming language: ")
print("Hello, " + name + ' you are ' + age + ' years old and your favorite programming language is ' + fav + '.')

2nd Challenge

Make a program to say that if the user's name is the same as yours.

name = input('What is your name: ')
if name == 'Daniel'(or your name):
(indentation/press tab) print('That is my name too!')
else:
(indentation) print('That is not my name.')

3rd Challenge

Make a program that takes two numbers from the user and adds them with a function.

def add(a,b):
(indentation) return a + b
num1 = int(input("Give me a number"))
num2 = int(input("Give me another number: "))
print(add(num1,num2))

4th Challenge

Make a program that makes a list of your friends names, and prints it out.

friends = ['Daniel', "John", "William", "Philip"]
print(friends)

5th Challenge

Make a program that loops through a list of names, and prints them all (without doing print (friends)) you HAVE to use a while function.

friends = ['Daniel', "John", "William", "Philip"]
i = 0
while i < 4:
(indentation) print (friends[i])
(indentation)i += 1

6th Challenge

Make a program to generate 100 random numbers and print them.(To do random, you have to do: import random then you would do random.randint(start, end(exclusive)))

import random
for i in range(1,101):
(indentation)print(random.randint(1,1000))

Final Challenge

Make a program to ask if the user likes Python, makes a function that takes a string and loops it 100 times, then if the user says yes, call the loop function with something like: I like it too. If the user does not like python, then call loop with something like: That's sad. If the user says someething else call loop on: restart program.

python = input("Do you like Python(y or n): ")
like = 'Wow. I like it to!!'
no_like = "That's sad."
other = "Please run the program again."
def loop(string):
(tab) for i in range(1,101):
(tab) (tab) print(string)
if python == 'y':
(tab)loop(like)
if python == 'n':
(tab)loop(no_like)
if python != 'n' and python != 'y':
(tab)loop(other)

Congratulations

Now you can go onto the advanced Python tutorial!