File tree 3 files changed +46
-0
lines changed
3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ def calculate_average (num_students ):
2
+ total_marks = 0
3
+ for _ in range (num_students ):
4
+ mark = float (input ("Enter student's mark: " ))
5
+ total_marks += mark
6
+
7
+ average = total_marks / num_students
8
+ return average
9
+
10
+ num_students = int (input ("Enter the number of students: " ))
11
+ average_marks = calculate_average (num_students )
12
+ print (f"The average marks of { num_students } students is: { average_marks } " )
Original file line number Diff line number Diff line change
1
+ def find_smallest_and_largest (n ):
2
+ # Initialize variables to store the largest and smallest numbers
3
+ largest = float ('-inf' )
4
+ smallest = float ('inf' )
5
+
6
+ for _ in range (n ):
7
+ num = int (input ("Enter a number: " ))
8
+
9
+ # Check if the number is the largest or smallest so far
10
+ if num > largest :
11
+ largest = num
12
+ if num < smallest :
13
+ smallest = num
14
+
15
+ print (f"The largest number is: { largest } " )
16
+ print (f"The smallest number is: { smallest } " )
17
+
18
+ if __name__ == "__main__" :
19
+ n = int (input ("Enter the total numbers: " ))
20
+ find_smallest_and_largest (n )
Original file line number Diff line number Diff line change
1
+ def sum_of_numbers_and_palindrome ():
2
+ num = int (input ("Enter a number: " ))
3
+ total_sum = sum (range (num + 1 ))
4
+
5
+ # Check if the number is a palindrome
6
+ num_str = str (num )
7
+ if num_str == num_str [::- 1 ]:
8
+ print (f"{ num } is a palindrome." )
9
+ else :
10
+ print (f"{ num } is not a palindrome." )
11
+
12
+ return total_sum
13
+
14
+ sum_of_numbers_and_palindrome ()
You can’t perform that action at this time.
0 commit comments