
There are Three Level in This Challenging Program. Beginner means someone who has just gone through an introductory Python course. He can solve some problems with 1 or 2 Python classes or functions. Normally, the answers could directly be found in the textbooks. Intermediate means someone who has just learned Python, but already has a relatively strong programming background from before. He should be able to solve problems that may involve 3 or 3 Python classes or functions.
There are Three Level in This Challenging Program. Beginner means someone who has just gone through an introductory Python course. He can solve some problems with 1 or 2 Python classes or functions. Normally, the answers could directly be found in the textbooks. Intermediate means someone who has just learned Python, but already has a relatively strong programming background from before. He should be able to solve problems that may involve 3 or 3 Python classes or functions. The answers cannot be directly be found in the textbooks. Advanced. He should use Python to solve more complex problems 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.
Hints:
Consider use range(#begin, #end) method
Solution:
l=[]
for i in range(2000, 3201):
if (i%7==0) and (i%5!=0):
l.append(str(i))
print(','.join(l))
Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
def fact(x):
if x == 0:
return 1
return x * fact(x - 1)
x=int(input())
print(fact(x))
Hints:
In case of input data being supplied to the question, it should be assumed to be a console input.
Consider use dict()
Solution:
n=int(input())
d=dict()
for i in range(1,n+1):
d[i]=i*i
print(d)
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
tuple() method can convert list to tuple
Solution:
values=input()
l=values.split(",")
t=tuple(l)
print(l)
print(t)
Hints:
Use __init__ method to construct some parameters
Solution:
class InputOutString(object):
def __init__(self):
self.s = ""
def getString(self):
self.s = input()
def printString(self):
print(self.s.upper())
strObj = InputOutString()
strObj.getString()
strObj.printString()
Hints:
If the output received is in decimal form, it should be rounded off to its nearest value (for example, if the output received is 26.0, it should be printed as 26) In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
import math
c=50
h=30
value = []
items=[x for x in input().split(',')]
for d in items:
value.append(str(int(round(math.sqrt(2*c*float(d)/h)))))
print(','.join(value))
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 from User
input_str = input()
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)
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
items=[x for x in input().split(',')]
items.sort()
print(','.join(items))
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
lines = []
while True:
s = input()
if s:
lines.append(s.upper())
else:
break;
for sentence in lines:
print(sentence)
Hints: In case of input data being supplied to the question, it should be assumed to be a console input. We use set container to remove duplicated data automatically and then use sorted() to sort the data.
Solution:
s = input()
words = [word for word in s.split(" ")]
print(" ".join(sorted(list(set(words)))))
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
value = []
items=[x for x in input().split(',')]
for p in items:
intp = int(p, 2)
if not intp%5:
value.append(p)
print(','.join(value))
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
values = []
for i in range(1000, 3001):
s = str(i)
if (int(s[0])%2==0) and (int(s[1])%2==0) and (int(s[2])%2==0) and (int(s[3])%2==0):
values.append(s)
print(",".join(values))
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
s = input()
d={"DIGITS":0, "LETTERS":0}
for c in s:
if c.isdigit():
d["DIGITS"]+=1
elif c.isalpha():
d["LETTERS"]+=1
else:
pass
print("LETTERS", d["LETTERS"])
print("DIGITS", d["DIGITS"])
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
s = input()
d={"UPPER CASE":0, "LOWER CASE":0}
for c in s:
if c.isupper():
d["UPPER CASE"]+=1
elif c.islower():
d["LOWER CASE"]+=1
else:
pass
print("UPPER CASE", d["UPPER CASE"])
print("LOWER CASE", d["LOWER CASE"])
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
a = input()
n1 = int( "%s" % a )
n2 = int( "%s%s" % (a,a) )
n3 = int( "%s%s%s" % (a,a,a) )
n4 = int( "%s%s%s%s" % (a,a,a,a) )
print(n1+n2+n3+n4)
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
values = input()
numbers = [x for x in values.split(",") if int(x)%2!=0]
print(",".join(numbers))
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
netAmount = 0
while True:
s = input()
if not s:
break
values = s.split(" ")
operation = values[0]
amount = int(values[1])
if operation=="D":
netAmount+=amount
elif operation=="W":
netAmount-=amount
else:
pass
print(netAmount)
Hints: In case of input data being supplied to the question, it should be assumed to be a console input.
Solution:
import re
value = []
items=[x for x in input().split(',')]
for p in items:
if len(p)<6 or len(p)>12:
continue
else:
pass
if not re.search("[a-z]",p):
continue
elif not re.search("[0-9]",p):
continue
elif not re.search("[A-Z]",p):
continue
elif not re.search("[$#@]",p):
continue
elif re.search("\s",p):
continue
else:
pass
value.append(p)
print(",".join(value))
Hints: In case of input data being supplied to the question, it should be assumed to be a console input. We use itemgetter to enable multiple sort keys.
Solution:
from operator import itemgetter, attrgetter
l = []
while True:
s = input()
if not s:
break
l.append(tuple(s.split(",")))
print(sorted(l, key=itemgetter(0,1,2)))
Thanks for Reading Share This Post
Sign in to join the discussion and post comments.
Sign in