Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the following program which prompts the user to enter two, 3-digit numbers. You can assume that the user will always enter a 3-digit number

image text in transcribedimage text in transcribed

image text in transcribed

Complete the following program which prompts the user to enter two, 3-digit numbers. You can assume that the user will always enter a 3-digit number when prompted. The program will then calculate and print the "special distance" between these two numbers. This is calculated as the sum of the absolute differences between each of the corresponding three digits in the two numbers. For example if the user enters 123 and 456, then the special distance is: The absolute difference between the first digit of 123 (1) and the first digit of 456 (4) is 3. The absolute difference between the second digit of 123 (2) and the second digit of 456 (5) is 3. The absolute difference between the third digit of 123 (3) and the third digit of 456 (6) is 3. The special difference is 3 + 3 + 3 = 9. Some examples of the completed program running are shown below. For example: Input Result 123 456 Enter a 3 digit number: 123 Enter a 3 digit number: 456 The special distance between 123 and 456 is 9 701 489 Enter a 3 digit number: 701 Enter a 3 digit number: 489 The special distance between 701 and 489 is 19 1 num1=input ("Enter a 3 digit number: ") 2 num2=input ("Enter a 3 digit number: ") Complete the following program which generates a username. The program: Prompts the user to enter their name. You can assume that the user will always enter their name in the format first name surname, where a single space character separates the first name from the surname. Prompts the user to enter a number between 1 and 999 (both inclusive) Will use the user's name to generate the alphabetical part of the username. This consists of the first letter of the first name followed by the first three letters of the surname. You can assume that the surname will always have at least 3 characters. Will zero-extend the number entered by the user so that it has 3 digits - this is the numerical part of the username. For example, if the user enters 1, this would be zero-extended to 001. If the user enters 15, this would be zero- extended to 015. Zero-extension is not required if the user has entered a 3 digit number Will print the username consisting of the alphabetical and numerical parts. Some examples of the program being run are shown below. For example: Input Result Damir Azhar Enter your name: Damir Azhar 1 Enter a number between 1 and 999 (both inclusive): 1 Your username is: dazh001 Ann Cameron Enter your name: Ann Cameron 22 Enter a number between 1 and 999 (both inclusive): 22 Your username is: acam022 Answer: (penalty regime: 0%) 1 name = input("Enter your name:") 2 number = input("Enter a number between 1 and 999 (both inclusive):")

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 Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

What is the principle of thermodynamics? Explain with examples

Answered: 1 week ago

Question

Explain the strength of acid and alkali solutions with examples

Answered: 1 week ago