(Python 3) (1) Prompt the user to enter two words and a number, storing each int
ID: 3593548 • Letter: #
Question
(Python 3) (1) Prompt the user to enter two words and a number, storing each into separate variables. Then, output those three values on a single line separated by a space.
Enter favorite color: yellow Enter pet's name: Daisy Enter a number: 6 You entered: yellow Daisy 6 First password: yellow_Daisy Second password: 6yellow6 Number of characters in yellow_Daisy: 12 Number of characters in 6yellow6: 8
In the compiler is working fine. However, Zybooks output is coming out different.
my codes:
favoriteColor = input('Enter favorite color: ')
pet = input('Enter pet's name: ')
num = input('Enter a number: ')
print("You entered:",favoriteColor, pet, num)
print('')
color = favoriteColor+'{}'
password1 = color.format('_')+pet
print('First password: '+password1)
password2 = num+favoriteColor+num
print('Second password: '+password2)
print('')
#Display the length of the two passwords by using the len #function.
print('Number of characters in yellow_Daisy:', len(password1))
print('Number of characters in 6yellow6:', len(password2))
yellow Daisy 6
Your output
Enter favorite color: Enter pet's name: Enter a number: You entered: yellow Daisy 6 First password: yellow_Daisy Second password: 6yellow6 Number of characters in yellow_Daisy: 12 Number of characters in 6yellow6: 8
5: Compare outputkeyboard_arrow_up
0 / 1
Input
blue Harvey 7
Your output
Enter favorite color: Enter pet's name: Enter a number: You entered: blue Harvey 7 First password: blue_Harvey Second password: 7blue7 Number of characters in yellow_Daisy: 11 Number of characters in 6yellow6: 6
Expected output
Enter favorite color: Enter pet's name: Enter a number: You entered: blue Harvey 7 First password: blue_Harvey Second password: 7blue7 Number of characters in blue_Harvey: 11 Number of characters in 7blue7: 6
Explanation / Answer
favoriteColor = input('Enter favorite color: ')
pet = input('Enter pet's name: ')
num = input('Enter a number: ')
print("You entered:",favoriteColor, pet, num)
print('')
color = favoriteColor+'{}'
password1 = color.format('_')+pet
print('First password: '+password1)
password2 = num+favoriteColor+num
print('Second password: '+password2)
print('')
print('Number of characters in',password1,':', len(password1))
print('Number of characters in',password2,':', len(password2))
# printing format is corrected
favoriteColor = input('Enter favorite color: ')
pet = input('Enter pet's name: ')
num = input('Enter a number: ')
print("You entered:",favoriteColor, pet, num)
print('')
color = favoriteColor+'{}'
password1 = color.format('_')+pet
print('First password: '+password1)
password2 = num+favoriteColor+num
print('Second password: '+password2)
print('')
print('Number of characters in',password1,':', len(password1))
print('Number of characters in',password2,':', len(password2))
# printing format is corrected
Enter favorite color: bule Enter pet's name: Harvey Enter a number: 7 You entered: bule Harvey 7 First password: bule_Harvey Second password: 7bule7 Number of characters in bule_Harvey : 11 Number of characters in 7bule7 : 6
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.