Absolute noob. What built-in functions to use for basic tasks in Python?

0 like 0 dislike
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!
by | 8 views

2 Answers

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? "))
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))

Related questions

0 like 0 dislike
6 answers
asked Apr 1, 2019 by Slavka_online
0 like 0 dislike
6 answers
asked Apr 1, 2019 by Slavka_online
0 like 0 dislike
1 answer
0 like 0 dislike
3 answers
asked Apr 5, 2019 by rgamretsky
110,608 questions
257,186 answers
33,912 users