Python
Python
print("\nMy Details:")
print(f"I am {name}, created by {creator_name}, for the purpose of {purpose}.")
print(f"Memory I consume is around {memory_size} and my speed is {speed} Ghz.")
def get_count(message):
count = int(input(message + ": "))
if count < 0:
print("Invalid input")
exit()
return count
def get_cost(product):
cost = float(input("Cost of "+product+": "))
if cost < 0:
print("Invalid input")
exit()
return cost
a4sheet_cost = get_cost("A4sheet")
pen_cost = get_cost("pen")
pencil_cost = get_cost("pencil")
eraser_cost = get_cost("eraser")
print("\nItems Details")
print("A4sheet:{:.2f}".format(a4sheet_cost))
print("Pen:{:.2f}".format(pen_cost))
print("Pencil:{:.2f}".format(pencil_cost))
print("Eraser:{:.2f}".format(eraser_cost))
else:
print("Provide a valid input")
while True:
total_people = int(input("Enter the total no of people in the area: "))
if total_people <= 0:
print("Invalid input")
break
continue_input = input("Do you want to continue (1) for yes (0) for no: ")
if continue_input == '0':
break
if number < 0:
print("factorial does not exist for negative numbers")
else:
factorial = 1
for i in range(1, number + 1):
factorial = factorial*i
if n1 < 0 or n2 < 0:
print("Starting and ending numbers must be greater than or equal to zero")
elif n1 > n2:
print("Invalid input!! Ending number should be greater than starting number")
else:
armstrongNo =[]
if seats_per_row <= 0:
print("Invalid Input")
else:
seats_number = int(input("Enter the seat number\n"))
# Use set to remove duplicates and then convert back to list for sorting
unique_words = sorted(set(words))
print(output_string)
def main():
word_dictionary={}
while True:
word=input("Enter the word:\n")
num_meanings=int(input("Enter the no of meanings:\n"))
if (num_meanings<=0):
print("Invalid Input")
return
meanings=[]
print("Enter the meanings:\n")
for _ in range(num_meanings):
meaning=input()
meanings.append(meaning)
word_dictionary[word]=meanings
choice=input("\nDo you want to add one more elements to the dictionary? If
yes, press 1, else press 0: ")
if choice=='0':
display_word(word_dictionary)
break
elif choice!='1':
print("Invalid Input")
display_word(word_dictionary)
break
def display_word(word_dictionary):
print("Here's the dictionary you've created:")
for word,meanings in word_dictionary.items():
print(f"{word}:{meanings}")
if __name__=='__main__':
main()
# Step 5: Separate odd and even plot numbers using list comprehension
odd_plots = [plot for plot in plots if plot % 2 != 0]
even_plots = [plot for plot in plots if plot % 2 == 0]
else:
# Display all residents
print("\n('NAME', 'AGE', 'DESIGNATION', 'BAND')")
for resident in List_of_Residents:
print(resident)
def find_lucky(number):
sm = 0
while number != 0:
temp = number % 10
sm += temp
number = number // 10
if sm % 2 == 0:
return 1
else:
return 0
if number <= 0:
print("Invalid Number")
else:
lucky = find_lucky(number)
if lucky == 1:
print(str(number) + " is lucky")
else:
print(str(number) + " is not lucky")
# farewell.py
import greet
# visualize.py
import bars
prime_numbers = []
# Call the function to find prime numbers within the given range
find_prime(start, end)
def fibonacci(month):
a, b = 0, 1
for i in range(month-2):
a, b = b, a + b
return b
if month<1 or month>12:
print("Invalid month")
else:
print("The amoeba size is ",result)
def funny_string(string):
# Check if the string length is less than 2
if len(string) < 2 or len(string) > 50:
return "Invalid string"
return "Funny"
import numpy as np
for i in range(4):
for j in range(4):
point = int(input(f"Quarter {i + 1}, Point {j + 1}: "))
john_statistics[i][j] = point
import numpy as np
pixel_values = []
print("Enter pixel values for the image (8 values):")
for i in range(1, 9):
value=int(input(f"Pixel {i}: "))
while value>256 or value<0:
print("Invalid input! Enter a value between 0 and 256")
value=int(input(f"Pixel {i}: "))
pixel_values.append(value)
image_matrix = np.array(pixel_values).reshape(2,4)
print("\nOriginal Array:")
print(np.array(pixel_values))
import numpy as np
# Display results
print("\nMean Temperature for", num_days, "Days:", format(mean_temperature, '.2f'))
print("Day with the Highest Temperature: Day", max_temperature_day, "Temperature:",
max_temperature)
print("Day with the Lowest Temperature: Day", min_temperature_day, "Temperature:",
min_temperature)
print("\nDays Sorted by Temperature (Ascending Order):")
for day, temperature in zip(sorted_days, sorted_temperatures):
print("Day", day, "Temperature", temperature)
import csv
# Open the CSV file using DictReader and display the contents of the first 10 rows
with open('OneDayInternational.csv', mode='r') as file:
reader = csv.DictReader(file)
row_count = 0
for row in reader:
if row_count < 10:
print(row)
row_count += 1
else:
break
35. Practice program: Filter the Countries Sachin has Played Against - CSV file
-------------------------------------------
import csv
import csv
# Update the total runs for the corresponding year in the dictionary
yearly_runs[year] = yearly_runs.get(year, 0) + runs
import json
def main():
print("Enter the value of N")
number=int(input())
sm=0
if number<=0:
print("Invalid input")
else:
for i in range(1,number+1):
sm+=i
if __name__=="__main__":
main()
def operation(my_tuple):
odd_sum = 0
even_sum = 0
for i in my_tuple:
if i % 2 == 0:
even_sum = even_sum + i
else:
odd_sum = odd_sum + i
return (even_sum, odd_sum)
# Driver method
def main():
print("Enter the number:")
N = int(input())
if checkOdd(N):
if isAutomorphic(N):
print("Automorphic Number")
else:
print("Not an Automorphic Number")
elif checkEven(N):
print("Not an Odd Number")
else:
print("Not an Even Number")
if __name__ == "__main__":
main()
def operation(mylist):
sm = 0
mx = float('-inf')
for i in mylist:
for j in i:
sm+=j
if j>mx:
mx=j
return mx,sm
name_list = []
for i in range(1, len(student_list), 2): # Start from index 1 and iterate every
alternate line
score = int(student_list[i].strip()) # Strip whitespace and convert to integer
if score >= 80:
name_list.append(student_list[i - 1].strip()) # Append the name from the
previous line