Blockchain Assignment 8
Blockchain Assignment 8
# conversion factor
conv_fac = 0.621371
# calculate miles
miles = kilometers * conv_fac
print('%0.2f kilometers is equal to %0.2f miles' %(kilometers,miles))
Output
2)
# calculate fahrenheit
fahrenheit = (celsius * 1.8) + 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))
Output
3)
Output 1
Enter a number: 2
Positive number
Output 2
Enter a number: 0
Zero
4)
Output 1
Enter a number: 43
43 is Odd
Output 2
Enter a number: 18
18 is Even
5)
year = 2000
if (year % 4) == 0:
if (year % 100) == 0:
if (year % 400) == 0:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
else:
print("{0} is a leap year".format(year))
else:
print("{0} is not a leap year".format(year))
Output
# Python program to find the largest number among the three input numbers
Output
7)
num = 407
Output
8)
# Python program to display all the prime numbers within an interval
lower = 900
upper = 1000
Output
9)
factorial = 1
Output
The factorial of 7 is 5040
10)
num = 12
Output
12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120
11)
Output
How many terms? 7
Fibonacci sequence:
0
1
1
2
3
5
8
12)
# initialize sum
sum = 0
Output 1
Output 2
13)
lower = 100
upper = 2000
# order of number
order = len(str(num))
# initialize sum
sum = 0
temp = num
while temp > 0:
digit = temp % 10
sum += digit ** order
temp //= 10
if num == sum:
print(num)
Output
153
370
371
407
1634