Professional Documents
Culture Documents
Python
Python
Python
# 2. Use range of indexes to print the third, fourth, and fifth item in the␣
↪list.
# 3. Use the insert method to add "lotus" as the second item in the flowers␣
↪list.
flowers.insert(1, "lotus")
print(flowers)
# 4. Create three lists of numbers and combine them as one data set and create␣
↪a violin plot for them.
plt.violinplot(combined_data)
plt.xlabel('Dataset')
plt.ylabel('Value')
plt.title('Violin Plot of Combined Datasets')
plt.show()
1
plt.plot(x, y2, label='cos(x)') # Command 3
plt.xlabel('x') # Command 4
plt.ylabel('y') # Set the label for y-axis
plt.legend() # Display legend
plt.title('Plot of sin(x) and cos(x)') # Set the title of the plot
plt.grid(True) # Show grid
plt.show()
sunflower
['rose', 'lotus', 'tulip']
['lily', 'lotus', 'sunflower', 'rose', 'lotus', 'tulip', 'hibiscus', 'orchid']
2
[ ]: while True:
print("\nMenu:")
print("1. Multiplication of a table")
print("2. Prime number check")
print("3. Sum of all numbers up to N using Recursion")
print("4. Exit")
choice = input("Enter your choice: ")
if choice == '1':
num = int(input("Enter a number: "))
print(f"Multiplication Table of {num}:")
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
elif choice == '2':
num = int(input("Enter a number: "))
if num <= 1:
print(f"{num} is not a prime number.")
else:
is_prime = True
for i in range(2, int(num**0.5) + 1):
3
if num % i == 0:
is_prime = False
break
if is_prime:
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")
elif choice == '3':
n = int(input("Enter a number: "))
def sum_up_to_n_recursive(n):
if n == 1:
return 1
return n + sum_up_to_n_recursive(n - 1)
print(f"Sum of all numbers up to {n} using recursion:␣
↪{sum_up_to_n_recursive(n)}")
Menu:
1. Multiplication of a table
2. Prime number check
3. Sum of all numbers up to N using Recursion
4. Exit
Enter your choice: 1
Enter a number: 2
Multiplication Table of 2:
2 x 1 = 2
2 x 2 = 4
2 x 3 = 6
2 x 4 = 8
2 x 5 = 10
2 x 6 = 12
2 x 7 = 14
2 x 8 = 16
2 x 9 = 18
2 x 10 = 20
Menu:
1. Multiplication of a table
2. Prime number check
3. Sum of all numbers up to N using Recursion
4. Exit
Enter your choice: 2
4
Enter a number: 45
45 is not a prime number.
Menu:
1. Multiplication of a table
2. Prime number check
3. Sum of all numbers up to N using Recursion
4. Exit
Enter your choice: 3
Enter a number: 88
Sum of all numbers up to 88 using recursion: 3916
Menu:
1. Multiplication of a table
2. Prime number check
3. Sum of all numbers up to N using Recursion
4. Exit
[ ]: