Answered step by step
Verified Expert Solution
Link Copied!

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 f-strings to generate a new string value
writing the main program to call your function
Instructions
Write a function create_password() expects two parameters: pet_name (a string) and fav_number (an integer).
The function returns a new password generated using the following pattern:
fav_number followed by the pet_name followed by the star * and fav_number 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
3
The function returns
3Angel*3
The main program outputs:
Your new password is "3Angel*3".
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 (i.e., a correctly-formed string).
assert create_password("Angel",3)=="3Angel*3"
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 f-strings.
Troubleshooting
If you are getting AssertionError make sure that your create_password() 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 create_password() function is returning the correct value. This error is likely due to the if __name__=='__main__': block printing the right value, but the function create_password() is not creating/returning the correct value.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions