Serial Number

Write a program that will generate a random serial number for the user. The user should enter a whole number between 1 and 100. A random number should be generated between 1 and 1000. The user number and the random number should be multiplied to create the product number. The user should then enter the first three initials of their surname which should be concatenated onto the product number to create the serial number. Finally, the serial number and the length of the serial number should be displayed to the user.

Enter a number between 1 and 100: 37
Enter the first three letters of your surname: STU
Serial Number: 14060STU8
READ user_number FROM USER

SET random_number TO RANDOM BETWEEN 1 AND 1000

SET product_number TO user_number * random_number

READ surname FROM USER

SET product_number TO product_number & surname

SET length_of_product_number TO LENGTH(product_number)

SET serial_number TO product_number & length_of_product_number

OUTPUT "Serial Number: ", serial_number

READ user_number FROM USER

SET random_number TO RANDOM BETWEEN 1 AND 1000

SET product_number TO user_number * random_number

READ surname FROM USER

SET product_number TO product_number & surname

SET length_of_product_number TO LENGTH(product_number)

SET serial_number TO product_number & length_of_product_number

OUTPUT "Serial Number: ", serial_number


# Required to create random numbers
import random

# Ask the user for a number between 1 and 100
user_number = int(input("Enter a number between 1 and 100: "))

# Generate a number between 1 and 1000
random_number = random.randint(1, 1000)

# Multiply user_number and the random_number together to create a product number
product_number = user_number * random_number

# Ask the user for the first three letters of their surname
surname = str(input("Enter the first three letters of your surname: "))

# Concatenate the product number and the surname together
product_number = str(product_number) + surname

# Get the length of the product number
length_of_product_number = len(product_number)

# Concatenate the product number and the length of the product number together
serial_number = product_number + str(length_of_product_number)

# Print out the Serial Number
print("Serial Number:", serial_number)

Extension

Extend the program to ask the user for another bit of information and add that onto the program before getting the serial numbers length.

Enter a number between 1 and 100: 37
Enter the first three letters of your surname: STU
Enter the first letter of your favourite colour: Y
Serial Number: 14060STUY9

Target

You should be able to use the Length predefined function to solve a problem.