Skip to content

Commit e9d117b

Browse files
committed
added several basic questions
1 parent 94850e2 commit e9d117b

File tree

1 file changed

+118
-1
lines changed

1 file changed

+118
-1
lines changed

100+ Python challenging programming exercises.txt

+118-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Level 2 Intermediate means someone who has just learned Python, but already has
77
Level 3 Advanced. He should use Python to solve more complex problem using more rich libraries functions and data structures and algorithms. He is supposed to solve the problem using several Python standard packages and advanced techniques.
88

99
2. Problem template
10-
Level
10+
11+
#----------------------------------------#
1112
Question
1213
Hints
1314
Solution
@@ -723,6 +724,122 @@ print "%s name is %s" % (Person.name, nico.name)
723724
#----------------------------------------#
724725

725726
#----------------------------------------#
727+
Question:
728+
Define a function which can compute the sum of two numbers.
729+
730+
Hints:
731+
Define a function with two numbers as arguments. You can compute the sum in the function and return the value.
732+
733+
Solution
734+
def SumFunction(number1, number2):
735+
return number1+number2
736+
737+
print SumFunction(1,2)
738+
739+
#----------------------------------------#
740+
Question:
741+
Define a function that can convert a integer into a string and print it in console.
742+
743+
Hints:
744+
745+
Use str() to convert a number to string.
746+
747+
Solution
748+
def printValue(n):
749+
print str(n)
750+
751+
printValue(3)
752+
726753

727754
#----------------------------------------#
755+
Question:
756+
Define a function that can convert a integer into a string and print it in console.
757+
758+
Hints:
759+
760+
Use str() to convert a number to string.
761+
762+
Solution
763+
def printValue(n):
764+
print str(n)
765+
766+
printValue(3)
767+
768+
#----------------------------------------#
769+
Question:
770+
Define a function that can receive two integral numbers in string form and compute their sum and then print it in console.
771+
772+
Hints:
773+
774+
Use int() to convert a string to integer.
775+
776+
Solution
777+
def printValue(s1,s2):
778+
print int(s1)+int(s2)
779+
780+
printValue("3","4") #7
781+
782+
783+
#----------------------------------------#
784+
Question:
785+
Define a function that can accept two strings as input and concatenate them and then print it in console.
786+
787+
Hints:
788+
789+
Use + to concatenate the strings
790+
791+
Solution
792+
def printValue(s1,s2):
793+
print s1+s2
794+
795+
printValue("3","4") #34
796+
797+
#----------------------------------------#
798+
Question:
799+
Define a function that can accept two strings as input and print the string with maximum length in console. If two strings have the same length, then the function should print al l strings line by line.
800+
801+
Hints:
802+
803+
Use len() function to get the length of a string
804+
805+
Solution
806+
def printValue(s1,s2):
807+
len1 = len(s1)
808+
len2 = len(s2)
809+
if len1>len2:
810+
print s1
811+
elif len2>len1:
812+
print s2
813+
else:
814+
print s1
815+
print s2
816+
817+
818+
printValue("one","three")
819+
820+
821+
822+
#----------------------------------------#
823+
Question:
824+
Define a function that can accept an integer number as input and print the "It is an even number" if the number is even, otherwise print "It is an odd number".
825+
826+
Hints:
827+
828+
Use % operator to check if a number is even or odd.
829+
830+
Solution
831+
def checkValue(n):
832+
if n%2 == 0:
833+
print "It is an even number"
834+
else:
835+
print "It is an odd number"
836+
837+
838+
checkValue(7)
839+
840+
841+
842+
843+
844+
728845

0 commit comments

Comments
 (0)