-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
123 lines (106 loc) · 4.35 KB
/
test.py
File metadata and controls
123 lines (106 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Get the sum of two numbers
print("Enter two numbers to get their sum: ")
a = input("Enter 1st value: ")
b = input("Enter 2nd value: ")
print("Sum of 1st and 2nd value: ", int(a) + int(b))
# Get the area of a square
print("Function to calculate area of a square")
a = input("Enter the side length of the square to get its area: ")
print("Area of square: ", int(a) * int(a))
print("Area of square: ", int(a) ** 2)
# Get the two float value numbers and print their average
print("Enter two float values to get their average: ")
a = float(input("Enter 1st float value: "))
b = float(input("Enter 2nd float value: "))
print("Average of 1st and 2nd float value: ", (a + b) / 2)
# Get the two int value numbers and print whether the first number is greater than or equal to the second number
print("Enter two int values to check if the first number is greater than or equal to the second number: ")
a = int(input("Enter 1st int value: "))
b = int(input("Enter 2nd int value: "))
print("a:", a, "b:", b, "a>=b:", a >= b)
# Get the length of the first name
print("Function to calculate length of the first name")
a = input("Enter the first name: ")
print("Length of the first name: ", len(a))
# Get the count of a specific letter in a string
print("Enter a string to count the number of times the letter '$' appears in it: ")
a = "Hi I earn $1000 per month. But I have to pay $500 for rent. And I spend $200 for food."
print("count of $ in the string: ", a.count("$"))
# Check if the given number is even or odd
print("Function to check if a number is even or odd")
a = input("Enter a number: ")
if (int(a) % 2 == 0):
print("Even")
else:
print("Odd")
# Get the largest of three numbers
print("Enter three numbers to get the largest number among them: ")
a = input("Enter 1st number: ")
b = input("Enter 2nd number: ")
c = input("Enter 3rd number: ")
if (int(a) > int(b) and int(a) > int(c)):
print("Largest number is: ", a)
elif (int(b) > int(a) and int(b) > int(c)):
print("Largest number is: ", b)
else:
print("Largest number is: ", c)
# Check if the given number is a multiple of 7
print("Function to check if a number is a multiple of 7")
a = int(input("Enter a number: "))
if (a % 7 == 0):
print("The number is multiple of 7")
else:
print("The number is not multiple of 7")
# Get the list of three movies from the user and print the list
print("Enter three movies to create a list of movies: ")
a = input("Enter 1st movie: ")
b = input("Enter 2nd movie: ")
c = input("Enter 3rd movie: ")
list = [a, b, c]
print("List of movies: ", list)
# Check if the given list is a palindrome
print("Function to check if a list is a palindrome")
palindrome = [1, 2, 3, 4, 5]
#palindrome = [1, 2, 3, 2, 1]
palindrome_copy = palindrome.copy() # [1, 2, 3, 2, 1]
palindrome_copy.reverse() # [1, 2, 3, 2, 1]
if (palindrome == palindrome_copy):
print("The list is a palindrome")
else:
print("The list is not a palindrome")
print("Is the list a palindrome? ", palindrome == palindrome_copy)
# Get the count of a specific element in a tuple
print("Function to count the number of times the letter 'A' appears in a tuple: ")
tuple = ("D", "C", "B", "A", "A", "B", "C", "D")
print("tuple.count('A'): ", tuple.count("A"))
# Get the sorted list of a given list
print("Function to sort a list: ")
list = ["D", "C", "B", "A", "A", "B", "C", "D"]
list.sort()
print("list sorted: ", list)
# print the keys and values of a dictionary
dict = {
"table": ("a piece of furniture", "lists of facts and statistics"),
"cat": "a small animals with fur, four legs, and a tail",
}
print("dict: ", dict)
# Get the unique elements from a collection
print("Function to get unique elements from a collection: ")
collection = {"python", "java", "c++", "python", "java", "c", "javascript"}
print("collection: ", len(collection))
print("collection: ", collection)
# Get the marks of three subjects from the user and print the marks in a dictionary
marks = {}
print("Enter the marks for the following subjects: ")
marks["Maths"] = float(input("Maths: "))
marks["Science"] = float(input("Science: "))
marks["English"] = float(input("English: "))
print("Marks: ", marks)
print(type(marks))
# Get the unique elements from a collection using a set
print("Function to get unique elements from a collection using a set: ")
unique_set = set()
unique_set.add(int(9))
unique_set.add("9.0")
unique_set.add(int(100))
print("unique_set: ", unique_set)