Last active
October 11, 2017 23:53
-
-
Save dangerrockstar/52b6f8919b13ff5425aaa99839e3e5ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
list=[1,2,3,4] | |
#blanklist=[] | |
def sum(): | |
for a in list: | |
b=0 | |
b=a | |
b=a+b | |
print b | |
def multiply(): | |
return | |
sum() | |
multiply() | |
'''Q.Define a function sum() and a function multiply() | |
that sums and multiplies (respectively) all the numbers in a list of numbers. | |
For example, sum([1, 2, 3, 4]) should return 10, and multiply([1, 2, 3, 4]) should return 24.''' | |
This file contains hidden or 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 find_longest_word(liststr): | |
li=[] | |
for a in liststr: | |
ob=len(a) | |
li.append(ob) | |
print max(li),'<-',li | |
find_longest_word(['python','is','great','language']) |
This file contains hidden or 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
a=(sum(ord(c) for c in 'HAPPY NEW YEAR TO ALL OF PROGRAMMER!')) | |
a=a-426 | |
print "%s" %a |
This file contains hidden or 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 is_palindrome(): | |
ob=list(raw_input("Enert a string: ")) | |
a=ob[::-1] | |
if a==ob: | |
print"true" | |
else: | |
print"flase" | |
is_palindrome() |
This file contains hidden or 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 lenoflist(): | |
list=[1,2,3,4,5] | |
count=0 | |
for a in list: | |
if a==a: | |
count+=1 | |
print count | |
lenoflist() | |
'''Q.Define a function that computes the length of a given list or string. | |
(It is true that Python has the len() function built in, but writing | |
it yourself is nevertheless a good exercise.)''' |
This file contains hidden or 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
list=[1,2,3,4] | |
#blanklist=[] | |
def sum1(): | |
print 'this sum of list:', sum((list)) | |
def multiply(): | |
count=1 | |
for x in list: | |
count*=x | |
print 'this multiply of list:',count | |
sum1() | |
multiply() | |
'''Q.Define a function sum() and a function multiply() | |
that sums and multiplies (respectively) all the numbers in a list of numbers. | |
For example, sum([1, 2, 3, 4]) should return 10, and multiply([1, 2, 3, 4]) should return 24.''' |
This file contains hidden or 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 map(liststr): | |
li=[] | |
for a in liststr: | |
ob=len(a) | |
li.append(ob) | |
print li,'\n',liststr | |
map(['python','is','great','language']) |
This file contains hidden or 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 max(x,y,z): | |
if x>=y and x>=z: | |
print x ,"X is grater then y and z" | |
return x | |
elif y>= x and y>= z: | |
print y ,"Y is grater then x and z" | |
return y | |
else: | |
print z ,"z is grater then x and y" | |
return z | |
max(110,120,130) | |
'''Q.Define a function max_of_three() that takes | |
three numbers as arguments and returns the largest of them.''' |
This file contains hidden or 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 max_in_list(li): | |
print max(li) | |
max_in_list([234,436,567,567,45645,5675]) |
This file contains hidden or 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 histogram(listnum): | |
for a in listnum: | |
print a*"*" | |
histogram([9,2,4]) |
This file contains hidden or 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 reverse(): | |
ob=list(raw_input("Enert a string: ")) | |
a=ob[::-1] | |
a=''.join(a) | |
print a | |
reverse() |
This file contains hidden or 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 translate(): | |
ob=str(raw_input("Enter Your string:")) | |
#print len(ob),'\n' | |
list=['a','e','i','o','u',''] | |
newlist=[] | |
for inrt in ob: | |
if inrt not in list: | |
newlist.append(inrt+'o'+inrt) | |
#print newlist | |
final=''.join(newlist) | |
print final | |
translate() | |
'''A, E, I, O, U''' |
This file contains hidden or 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 vowel(): | |
print "Please on Caps Lock " | |
list=['A','E','I','O','U','Y'] | |
a=raw_input("Enert You Word Check Vowel Or Not: ") | |
if a in list: | |
print "True" | |
else: | |
print "False" | |
vowel() | |
'''Q.Write a function that takes a character | |
(i.e. a string of length 1) and returns True if | |
it is a vowel, False otherwise.''' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment