0 like 0 dislike
15 views
Make your first steps in learning programming. Started a couple weeks ago.
The challenge is that we need to ask the user to enter the name of the animal and numbers. Using the number entered by the user, you need to ask the user to enter as many flowers, each on a separate line. After the user completes the input colors, the program should print a line with the name of the colors entered by the user.
Looks like this(user input in bold):

Enter an animal: cat
How many colors: 4

Color 1: white
Color 2: red
Color 3: blue
4 Color: brown

white cat
red cat
blue cat
brown cat

I started like this:

``colors = ["red", "blue", "black", "white", "yellow", "orange", "purple", "brown", "grey", "gray", "silver", "green"] userAnimal = input("Enter an animal: ") userNumber = input("How many colors: ") userNumber = int(userNumber)``

And then quite got up :(
Share the knowledge. Thank you!
| 15 views

0 like 0 dislike
Certainly strange that in two weeks you got to cycles.
``user_number = 4 user_colors = [] while len(user_colors) < user_number: user_colors.append(input("Color? "))``
by
0 like 0 dislike
Here is the solution for your problem:

``animal = input('Enter an animal: ') try: input_colors = input('How many colors? ') num_colors = int(input_colors) except ValueError: print('%s is not a number' % input_colors) exit() colors = [] for i in range(num_colors): colors.append(input('Color %s:' % (i + 1))) for color in colors: print('%s %s' % (color, animal))``
by

0 like 0 dislike