Skip to content
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

Update 100+ Python challenging programming exercises.txt #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 15 additions & 15 deletions 100+ Python challenging programming exercises.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ for i in range(2000, 3201):
if (i%7==0) and (i%5!=0):
l.append(str(i))

print ','.join(l)
print(','.join(l))
#----------------------------------------#

#----------------------------------------#
Expand All @@ -57,8 +57,8 @@ def fact(x):
return 1
return x * fact(x - 1)

x=int(raw_input())
print fact(x)
x=int(input("Insert a number: "))
print(fact(x))
#----------------------------------------#

#----------------------------------------#
Expand All @@ -77,12 +77,12 @@ In case of input data being supplied to the question, it should be assumed to be
Consider use dict()

Solution:
n=int(raw_input())
n=int(input("Insert a number: "))
d=dict()
for i in range(1,n+1):
d[i]=i*i

print d
print (d)
#----------------------------------------#

#----------------------------------------#
Expand All @@ -102,11 +102,11 @@ In case of input data being supplied to the question, it should be assumed to be
tuple() method can convert list to tuple

Solution:
values=raw_input()
values=input("Insert a sequence of comma-separated numbers: ")
l=values.split(",")
t=tuple(l)
print l
print t
print (l)
print (t)
#----------------------------------------#

#----------------------------------------#
Expand Down Expand Up @@ -164,11 +164,11 @@ import math
c=50
h=30
value = []
items=[x for x in raw_input().split(',')]
items=[x for x in input("Insert a sequence of comma-separated numbers: ").split(',')]
for d in items:
value.append(str(int(round(math.sqrt(2*c*float(d)/h)))))

print ','.join(value)
print (','.join(value))
#----------------------------------------#

#----------------------------------------#
Expand All @@ -188,17 +188,17 @@ Hints:
Note: In case of input data being supplied to the question, it should be assumed to be a console input in a comma-separated form.

Solution:
input_str = raw_input()
dimensions=[int(x) for x in input_str.split(',')]
rowNum=dimensions[0]
colNum=dimensions[1]
input_str = input("Insert 2 comma-separated digits: ")
dimensions = [int(x) for x in input_str.split(',')]
rowNum = dimensions[0]
colNum = dimensions[1]
multilist = [[0 for col in range(colNum)] for row in range(rowNum)]

for row in range(rowNum):
for col in range(colNum):
multilist[row][col]= row*col

print multilist
print (multilist)
#----------------------------------------#

#----------------------------------------#
Expand Down