Python Interview Questions 9


71. Example of for 
foods = ['apple', 'banana', 'grapes', 'mango']
for f in foods:
    print(f)
    print(len(f))

72. function example
def cisco():
    print("Python, fucntions are cool!")
cisco()

def bitcoin_to_usd(btc):
    amount = btc*527
    print(amount)

bitcoin_to_usd(3.85)

73. Example of if else
name = "Lucy"
if name is "Manish":
    print("hey there Manish")
elif name is "Lucy":
    print("What's up Lucy")
elif name is "Sammy":
    print("What's up Sammy")
else:
    print("Please sign up for the Site!")

74. Example of key argument 
def dumb_sentence(name='manish',action='ate',item='tuna'):
    print(name,action,item)

dumb_sentence()
dumb_sentence("Sally", "plays", "gently")
dumb_sentence(item ='awesome', action= 'is')

75. Example of range
for x in range(10):
    print("Hello manish")

for x in range(5, 12):
    print(x)
for x in range(10, 40, 5):
    print(x)

No comments:

Post a Comment