Lab Report 04
Lab Report 04
RAWALPINDI
Lab Number # 04
SUBMITTED TO:
SUBMITTED BY:
Muhammad Talha
REG NO # 481402
Hardware/Software required:
Hardware:
. Laptop
Software Tool:
. VS Code
CODE:
numbers = []
while True:
num_input = input("Enter a number (or 'done' to finish): ")
if num_input.lower() == 'done':
break
try:
num = float(num_input)
numbers.append(num)
except ValueError:
print("Invalid input. Please enter a valid number or 'done' to finish.")
squared_numbers = [num ** 2 for num in numbers]
print("Squared numbers of the given number will be:")
for squared_num in squared_numbers:
print(squared_num)
Output:
CODE:
• Write a python program that finds the length of the largest word in:
• A list
• A dictionary If the list is my_list = [‘write’, ‘a’, ‘python’ ‘program’] and my_dict = {1:
‘write’, 2: ‘ a’, 3: ‘python’, 4: ‘program’]
• The output should be:
• The word with the longest length is: program.
CODE:
max_length_list = 0
longest_word_list = ""
for word in my_list:
if len(word) > max_length_list:
max_length_list = len(word)
longest_word_list = word
max_length_dict = 0
longest_word_dict = ""
for word in my_dict.values():
if len(word) > max_length_dict:
max_length_dict = len(word)
longest_word_dict = word
Conclusion: