Skip to content

added alternative simpler solutions #158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions 100+ Python challenging programming exercises for Python 3.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions 100+ Python challenging programming exercises.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down