VITyarthi Python Essentials Module 3 Challenging Task Solution

Challenging Task-Peer Assessment 1

Find the average of five different subject marks.

     Sample Input:
         Subject 1: 66
         Subject 2: 77
         Subject 3: 88
         Subject 4: 99
         Subject 5: 55

     Sample Output:
     77

Solution

				
					subject1 = 66
subject2 = 77
subject3 = 88
subject4 = 99
subject5 = 55
average = (subject1 + subject2 + subject3 + subject4 + subject5) / 5
print("The average of the subject marks is", average)

				
			

Challenging Task-Peer Assessment 2

Convert the temperature in Celsius to Fahrenheit.


Sample Input:
Celsius = 30


Sample Output: 86

Solution

				
					def celsius_to_fahrenheit(celsius):
    fahrenheit = (celsius * 9/5) + 32
    return fahrenheit

celsius = 30
fahrenheit = celsius_to_fahrenheit(celsius)
print("Temperature in Celsius: ", celsius)
print("Temperature in Fahrenheit: ", fahrenheit)


				
			

Challenging Task-Peer Assessment 3

Write a program to do exchange of two numbers using addition and subtraction without using temporary variables.


Sample Input:
a=150
b=270


Sample Output:
a=270
b=150

Solution

				
					a = 150
b = 270

a = a + b
b = a - b
a = a - b

print("a =", a)
print("b =", b)

				
			

Challenging Task-Peer Assessment 4

Write a program to do exchange of two numbers using bitwise operators.

Sample Input:
a=150
b=270


Sample Output:
a=270
b=150

Solution

				
					a = 150
b = 270

# Using bitwise XOR to exchange the values
a = a ^ b
b = a ^ b
a = a ^ b

print("a =", a)
print("b =", b)


				
			

Challenging Task-Peer Assessment 5

Find the given number is even.


Sample Input:
a=100


Sample Output:
The number is even

Solution

				
					a = 100
if a%2 == 0:
    print("The number is even")
else:
    print("The number is odd")



				
			

Challenging Task-Peer Assessment 6

Print the last digit of the given number.


Sample Input: 256


Sample Output: 6

Solution

				
					number = 256

last_digit = number % 10

print(last_digit)

				
			

Challenging Task-Peer Assessment 7

Verify the given number is divisible by 5.


Sample Input: 255


Sample Output: The number is divisible by 5

Solution

				
					num = int(input("Enter a number: "))
if num % 5 == 0:
    print("The number is divisible by 5")
else:
    print("The number is not divisible by 5")

				
			

If you find anything wrong in this Solution, feel free to reach us in the comment section.

Sharing Is Caring:

Leave a Comment