This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Multiplication table (from 1 to 10) in Python | |
num = int(input("Please enter the value: ")) | |
# To take input from the user | |
# num = int(input("Display multiplication table of? ")) | |
# Iterate 10 times from i = 1 to 10 | |
for i in range(1, 11): | |
print(num, 'x', i, '=', num*i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Program to check if a number is prime or not | |
num = 29 | |
# To take input from the user | |
#num = int(input("Enter a number: ")) | |
# define a flag variable | |
flag = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num = int(input("Enter a number: ")) | |
if (num % 2) == 0: | |
print("{0} is Even".format(num)) | |
else: | |
print("{0} is Odd".format(num)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num = float(input("Enter a number: ")) | |
if num >= 0: | |
if num == 0: | |
print("Zero") | |
else: | |
print("Positive number") | |
else: | |
print("Negative number") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
num = float(input("Please eneter a value: ")) | |
if num >0: | |
print("Positive") | |
elif num < 0: | |
print("negative") | |
else: | |
print("zero") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import random | |
Random_side = random.randint(0,1) | |
if random_side == 1: | |
print(“Heads”) | |
else: | |
print(“Tails”) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Program to convert temperature in celsius to fahrenheit | |
# change this value for a different result | |
celsius = float(input("Please enter the value: ") ) | |
# calculate fahrenheit | |
fahrenheit = (celsius * 1.8) + 32 | |
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Program to convert temperature in celsius to fahrenheit | |
# change this value for a different result | |
celsius = 37.5 | |
# calculate fahrenheit | |
fahrenheit = (celsius * 1.8) + 32 | |
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# import random | |
import random | |
# prints a random value from the list | |
list1 = [1, 2, 3, 4, 5, 6] | |
print(random.choice(list1)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taking kilometers input from the user | |
kilometers = float(input("Enter value in kilometers: ")) | |
# conversion factor | |
conv_fac = 0.621371 | |
# calculate miles | |
miles = kilometers * conv_fac | |
print(f"{kilometers} is equal {miles}") |
NewerOlder