Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this lab, you will practice: writing a function to match the specifications using string concatenation or f - strings to generate a new string
In this lab, you will practice:
writing a function to match the specifications
using string concatenation or fstrings to generate a new string value
writing the main program to call your function
Instructions
Write a function createpassword expects two parameters: petname a string and favnumber an integer
The function returns a new password generated using the following pattern:
favnumber followed by the petname followed by the star and favnumber again see the example below
Create a program that gets a pet name and a favorite number as input from the user, calls the above function, and then prints the output as shown below.
Example
Input:
Angel
The function returns
Angel
The main program outputs:
Your new password is Angel
Note that the double quotes are part of the output.
The assert in the provided template is checking that this function call is returning the correct value ie a correctlyformed string
assert createpasswordAngelAngel
Hints
Remember that you cannot directly concatenate an integer and a string you need to convert an integer into a string using either str or by using fstrings.
Troubleshooting
If you are getting AssertionError make sure that your createpassword function is returning the correct value.
If you are failing the Unit Tests but passing all of the "Compare Output" tests: make sure that your createpassword function is returning the correct value. This error is likely due to the if namemain: block printing the right value, but the function createpassword is not creatingreturning the correct value.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started