0% found this document useful (0 votes)
34 views2 pages

Lab3.ipynb - Colaboratory

The document contains code that takes user input of names and student IDs to generate a login ID in the format of first initial, first 3 letters of the last name, and last 4 digits of the student ID. It then takes user input of numbers and sorts them in ascending and descending order, printing the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views2 pages

Lab3.ipynb - Colaboratory

The document contains code that takes user input of names and student IDs to generate a login ID in the format of first initial, first 3 letters of the last name, and last 4 digits of the student ID. It then takes user input of numbers and sorts them in ascending and descending order, printing the results.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

2/13/23, 11:03 PM Lab3.

ipynb - Colaboratory

name_1 = input("Please enter your first name: ") #get first name
name_2 = input("Please enter your family name: ") #get family name
id = input("Please enter your student id: ") #get student id
Ulearn = [] #create list
Ulearn.append(f'{name_1}') #add item to the end of the list
Ulearn.append(f'{name_2}')
Ulearn.append(f'{id}')
name1 = [] #create list
for i in Ulearn[0]: #read every character in name_1 with index 0
  name1.append(i) 
first_name = name1[0].lower() #get all lowercase string
name2 = Ulearn[1]
family_name = name2[0:3].lower() #use indices to get firt to third value
studentid = Ulearn[2]
number = []
for c in studentid:
  number.append(c)
length = len(number)
digits = studentid[length - 4:]
Ulearn_id = "_".join([first_name, family_name, digits]) #concatenates a list of string with underscore
print("Your Ulearn login id is: ",f'{Ulearn_id}')

Please enter your first name: Matthew


Please enter your family name: Kong
Please enter your student id: 20001243
Your Ulearn login id is: m_kon_1243

num_1 = input("Please enter number 1: ") #get number
num_2 = input("Please enter number 2: ")
num_3 = input("Please enter number 3: ")
num_4 = input("Please enter number 4: ")

num_list = [] #create list
num_list.append(num_1) #add number to the end of the list
num_list.append(num_2)
num_list.append(num_3)
num_list.append(num_4)
Max = max(num_list) #get largest number from num_list
num_list.remove(Max) #remove largest number from num_list  
Min = min(num_list) #get smallest number from num_list
num_list.remove(Min) #remove smallest number from num_list  
Max2 = max(num_list) #find second largest number
Min2 = min(num_list) #find second smallest number
as_order = f"{Min}\t{Min2}\t{Max2}\t{Max}" #Add space between integers
de_order = f"{Max}\t{Max2}\t{Min2}\t{Min}" #Add space between integers
print(f'The ascedning order is: {as_order}')
print(f'The·descending·order·is:·{de_order}')

  

Please enter number 1: 67


Please enter number 2: 34
Please enter number 3: 34
Please enter number 4: 87
The ascedning order is: 34 34 67 87
The descending order is: 87 67 34 34

https://colab.research.google.com/drive/1D0qM9c3T6XF5G0ONPAhopB3uRl_HP_vK#scrollTo=kGM5isNuBnKr&printMode=true 1/2
2/13/23, 11:03 PM Lab3.ipynb - Colaboratory

check 25s completed at 10:24 PM

https://colab.research.google.com/drive/1D0qM9c3T6XF5G0ONPAhopB3uRl_HP_vK#scrollTo=kGM5isNuBnKr&printMode=true 2/2

You might also like