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
def cube(x=2): | |
print('Cube of',x, 'is', x**3) | |
def equal(x,y): | |
return x==y | |
cube() | |
cube(5) | |
print(equal('a','b')) | |
print(equal('s','s')) |
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
def volume(l=1,b=1,h=1): | |
return l*b*h | |
v1=volume() | |
v2=volume(10,5,2) | |
v3=volume(b=8) | |
v4=volume(5,7) | |
print(v1) | |
print(v2) | |
print(v3) |
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
def dollartorupee(amt,exc): #Void | |
print('Rs', amt*exc) | |
def dollartorupee2(amt,exc): #Non-Void | |
print('Rs', amt*exc) | |
return amt*exc | |
dollartorupee(100,7) | |
print('Rs', dollartorupee2(500,7)) |
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
t1 = input('Welcome to Computer Tutor!\n Please enter the first time:') | |
t2 = input('Please enter thr second time:') | |
print(int(t2[:2])-int(t1[:2]),'hours', int(t2[2:])-int(t1[2:]),'minutes') |
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
print('Pounds | Kg') | |
for i in range(1,100,10): | |
print('{} | {}'.format(i,i*0.453)) |
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
print('Miles | Km') | |
for i in range(1,100,10): | |
print('{} | {}'.format(i,i*1.609)) |
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
MONTHS = ['January', 'February', 'Match', 'April', 'May', 'June', | |
'July', 'August', 'September', 'October', 'November', 'December'] | |
def date_convert(s): | |
y = s[:4] | |
m = int(s[5:-3]) | |
d = s[8:] | |
month_name = MONTHS[m-1] | |
result= month_name + ' ' + d +' '+ y | |
return result |
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
n = int(input("Enter an Integer: ")) | |
x = 0 | |
if n > 0: | |
for i in range(n, 2*n+1): | |
x += i | |
else: | |
for i in range(2*n, n+1): # for negative n, we need to reverse start & end of range | |
x += i | |
print(x) |
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
def feet_to_inches(x): | |
return x*12 | |
def feet(): | |
x = int(input('Enter feet : ')) | |
return x | |
def disp_inches(x): | |
print('Number of inches :', x) |
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
def numberedDay(firstDay, dayNumber): | |
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] | |
firstIndex = days.index(firstDay) | |
endIndex = (firstIndex + int(dayNumber) - 1) % 7 | |
return days[endIndex] | |
year = input("Year: ") | |
firstDay = input("First day of the year (e.g. 'Monday'): ") | |
dayNumber = input("Day number: ") |