From 77436fc072e0479f5996846c5ccb1563a45ae0fd Mon Sep 17 00:00:00 2001 From: leobraintech <146356264+leobraintech@users.noreply.github.com> Date: Tue, 3 Oct 2023 11:14:06 +0200 Subject: [PATCH] Update 100+ Python challenging programming exercises.txt Changes: parenthesis for function "print" --- ...thon challenging programming exercises.txt | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/100+ Python challenging programming exercises.txt b/100+ Python challenging programming exercises.txt index 97af5aaf..e852f71c 100644 --- a/100+ Python challenging programming exercises.txt +++ b/100+ Python challenging programming exercises.txt @@ -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)) #----------------------------------------# #----------------------------------------# @@ -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)) #----------------------------------------# #----------------------------------------# @@ -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) #----------------------------------------# #----------------------------------------# @@ -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) #----------------------------------------# #----------------------------------------# @@ -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)) #----------------------------------------# #----------------------------------------# @@ -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) #----------------------------------------# #----------------------------------------#