diff --git a/100+ Python challenging programming exercises for Python 3.md b/100+ Python challenging programming exercises for Python 3.md index c4ba62c4..30e36fed 100644 --- a/100+ Python challenging programming exercises for Python 3.md +++ b/100+ Python challenging programming exercises for Python 3.md @@ -90,6 +90,12 @@ for i in range(1,n+1): print(d) ``` +Another Solution: +```python +n=int(input("Enter the value of n:")) +d={i:i*i for i in range(1, n+1)} +print(d) +``` ### Question 4 Level 1 @@ -549,6 +555,19 @@ while True: print(sorted(l, key=itemgetter(0,1,2))) ``` +Another Solution: +```python +from operator import itemgetter +lst=[] +while True: + l=input() + if l==" ": + break + else: + lst.append(tuple(l.split(','))) +lst.sort(key=itemgetter(0,1,2)) +print(lst) +``` ### Question 20 Level 3 @@ -679,6 +698,12 @@ def square(num): print(square(2)) print(square(3)) ``` +Another Solution +```python +n=int(input('enter value of n:')) +square=n**2 +print(square) +``` ### Question 24 Level 1 diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index 97af5aaf..7843c16c 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -85,6 +85,16 @@ for i in range(1,n+1): print d #----------------------------------------# +#----------------------------------------# + +Another Solution + +n=int(input("Enter the value of n:")) +d={i:i*i for i in range(1, n+1)} +print(d) + +#----------------------------------------# + #----------------------------------------# Question 4 Level 1 @@ -540,6 +550,21 @@ while True: print sorted(l, key=itemgetter(0,1,2)) #----------------------------------------# +#----------------------------------------# +Another Solution: +from operator import itemgetter +lst=[] +while True: + l=input() + if l==" ": + break + else: + lst.append(tuple(l.split(','))) +lst.sort(key=itemgetter(0,1,2)) +print(lst) + +#----------------------------------------# + #----------------------------------------# Question 20 Level 3 @@ -666,6 +691,13 @@ print square(2) print square(3) #----------------------------------------# +#----------------------------------------# +Another Solution: +n=int(input('enter value of n:')) +square=n**2 +print(square) +#----------------------------------------# + #----------------------------------------# Question 24 Level 1