Question

In: Computer Science

Python create a program Danny works for the government and is making a change. The chsnge...

Python create a program
Danny works for the government and is making a change. The chsnge is to create a 4 - digit ID frim the Original 12 - digit ID currently used for carts. The algorith established by Danny is as follows:
Find the sum of all 12 digits.
Extract the last 3 digits and multiply by 10.
Finally, add the results of the first twiboperations
Note:
If in step 3, there are more than 4 digits (x> 9999) , you must choose the last 4.
For example : 98012345 => 2345
If contains lesd than 4 digits ( x < 999), you must add 1, 000 to it. For example: 99 => 1099
Input Format
The first line of input contsins an integer
T (<= T < =100) , the number of test cases that follow. For each test cases, it will contains the 12- digit ID
Constraints
T ( 1 <=T <=100)
Output format
Print a single line per case, where the result is the 4- digit ID with the established rules.
Sample Input 0
3
465467984123
168198708712
620689713546
Sample Output

1289
7178
5519
Sample Input 1

two
416315410123
978643112002
978643112002
Sample Output 1
1261
1063

Solutions

Expert Solution

The last three digits of the ID is retrieved by using modulation operation. As shown in the below

last_three = (ID % 1000)

Code:

t = int(input()) #read the number of inputs

#for each input calculate the new ID

for _ in range(t):

n = int(input()) # 12 digit ID

total_sum = 0 # stores total sum of digits

last_three = (n%1000) * 10 # retrive the last digits from the ID

while(n>0):

total_sum+=n%10

n=n//10

new_id = total_sum + last_three # new Id generation

# new ID should be 4 digits

if new_id > 9999:

new_id = (n%10000)

elif new_id < 999:

new_id += 1000

#print the new ID

print(new_id)



Output:

1
978643112002
1063

Please refer to the screenshots below for correct indentations


Related Solutions

Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
FOR PYTHON: Write a python program for a car salesperson who works a five day week....
FOR PYTHON: Write a python program for a car salesperson who works a five day week. The program should prompt for how many cars were sold on each day and then prompt for the selling price of each car (if any) on that day. After the data for all five days have been entered, the program should report the total number of cars sold and the total sales for the period. See example output. NOTE: duplicate the currency format shown...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will...
Create a program (Python) YourFirstnameLastnameA06b.py to ask the user to create a password: The user will first enter a password, then enters the same password again; If the second input is the same as first one, the user successfully creates the password. Print “Well done.”; Otherwise, the user will be directed to repeat the whole process (go to step 1.)
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Using Python, create a program that will act as a number convertor. This program will convert...
Using Python, create a program that will act as a number convertor. This program will convert an input decimal integer into binary and hexadecimal formats. a) Define a main function named numberconvertor(). Inside the main function, write all the logic of your code. [5% marks] b) Looping indefinitely (Hint: use infinite while loop), the program should give the user the 3 options given below and allow the user to select one among them. [15% marks] 1. converting a decimal number...
Need the following program in Python: Create a program that calculates the estimated duration of a...
Need the following program in Python: Create a program that calculates the estimated duration of a trip in hours and minutes. This should include an estimated date/time of departure and an estimated date/time of arrival. Arrival Time Estimator Enter date of departure (YYYY-MM-DD): 2016-11-23 Enter time of departure (HH:MM AM/PM): 10:30 AM Enter miles: 200 Enter miles per hour: 65 Estimated travel time Hours: 3 Minutes: 5 Estimated date of arrival: 2016-11-23 Estimated time of arrival: 01:35 PM Continue? (y/n):...
How to do this in Python (using Lists): Create a python program that allows a user...
How to do this in Python (using Lists): Create a python program that allows a user to display, sort and update as needed a List of U.S States containing the State Capital and State Bird. You will need to embed the State data into your Python code. The user interface will allow the user to perform the following functions: 1. Display all U.S. States in Alphabetical order along with Capital and Bird 2. Search for a specific state and display...
IN PYTHON create a python program that accepts input from the user in the following sequence:...
IN PYTHON create a python program that accepts input from the user in the following sequence: 1. Planet Name 2. Planet Gravitational Force(g) for data, use the planets of our solar system. The data input is to be written in 2 separate lists, the names of which are: 1. planetName 2. planet GravitationalForce(g) A third list is required that will store the weight of a person with mass of 100kg, the formula of which is: W=mg(where m is mass of...
I am having a trouble with a python program. I am to create a program that...
I am having a trouble with a python program. I am to create a program that calculates the estimated hours and mintutes. Here is my code. #!/usr/bin/env python3 #Arrival Date/Time Estimator # # from datetime import datetime import locale mph = 0 miles = 0 def get_departure_time():     while True:         date_str = input("Estimated time of departure (HH:MM AM/PM): ")         try:             depart_time = datetime.strptime(date_str, "%H:%M %p")         except ValueError:             print("Invalid date format. Try again.")             continue        ...
write a python program, please. Create a program that uses the Gettysburg Address as input and...
write a python program, please. Create a program that uses the Gettysburg Address as input and outputs a list of tuples for every two words. For example: [('Four', 'score'),('and', 'seven'), ...].
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT