0% found this document useful (0 votes)
187 views49 pages

Python HandsOn

Uploaded by

meet jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
187 views49 pages

Python HandsOn

Uploaded by

meet jain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

& Dashboard / My courses / Python / Introduction to Python / Welcome Message

Practice program: Welcome Message


Description Code Editor Grading view

File List Save Compile 8&


Run Evaluate Full screen Description

Welcome.py D
1 print ("Welcome to Data Science Course!")

44388
Practice program: Alien's Visit
Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen D

alien.py 0
1 name=input("Enter the name:
2 print ("Hello "+name+"! Welcome to our planet Earth.")
-
Error Q gmail Search M Ffundamental Skill Primer
-
Accer x Pragramming using Python Intrc x X

Ô https/laccenturelearning. tekstaccom/mod/vpl/forms/edit,php?id=59408userid-44388# A

File List Save Compile & Run Evaluate Full screen Description

AI.py
name=input (" Enter the name: \n")
2 creatorName=input (" Enter the creator name:\n")
3 purpose=input ("Enter the purpose: \n")
4 memorySize=input ("Enter the memory size:\n")
5 speed=input ("Enter the speed: \n")
6 , .
7 print ("My Details:\n\n I am "name " created by "*creatorName ",
for the purpose of "*purpose-" \n\n Memory I consume is around "*memorySize *"
and my speed is

44388

44388
44388

ENG 8:17 PM
IN
) D 1/18/2024
73F Q Search
Partly cloudy
Error a gmail- Search x MFundamental Skill Primer- Accer x>Programming using Python New x +
Ô
https//accenturelearning tekstaccom/mod/vpl/forms/edit.php?id=5941&userid=44388# A

Practice program: News Report Generation


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

news_report.py
1
DOO
dead=int(input("Dead Count: \n"))
2
3- if dead <@:
4 print ("Invalid input")

6- else:
7 injured=int (input ("Injured Count:\n"))
8
9
10
if injured<e:
print("Invalid
44388
input")
11
12 else:
13 safe=int (input ("Safe Count:\n"))
14
15 if safece:
16
17
18 else:
print("Invalid
a*388
input")

19 print ("\nTSUNAMI REPORT OF JAPAN\n")


20 print("The number of people\n")
21 print(f"Dead: {dead}\n")
22 print(f"Injured: {injured} \n")
23 print(f"Safe: (safe}\n")
24 print("Please help the people who are sufferingl !|")
<

73F Q Search
ENG 8:2
)D
Partly cloudy IN 1/18
Error a -
gmail Search x M Fundamental Skaill Primer- Accer x Programming using Python Stat x +
Ô https/laccenturelearning. tekstaccom/mod/wpl/forms/edit.php?id=59428uuserid=44388#

Practice program: Stationary Shop


Description Code Editor Grading view

File List Save Compile 8&


Run Evaluate Full screen Description

Stationary.py D
1
1388
2 sheet=float (input ("Cost of A4sheet: \n"))
3- if sheet<@:
4 print ("Invalid input")
5
else:
6 pen=float (input ("Cost of pen: \n"))
if pen<e:
7
8
print("Tnvalid snput")388
9 else:
1e pencil=float(input ("Cost of pencil:\n"))
11 - if pencil<e:
12 print ("Invalid input")
13 else:
14 eraser=float (input ("Cost of eraser;\n"))
if eraser<e:
15
16
17 else:
print ("Invalid input")
print ("\nItems Details\n")
88
18
19 print("A4sheet : {:.2f}".format (sheet ))
22 print ("Pen:{:.2f}".format
.
(pen) )
21 print ("Pencil:{: 2f}".format (pencil))
22 print("Eraser : {: .2f}".format (eraser))

73F ENG 8:24


Partly cloudy Q Search
IN 1/18/
db.books.updateMany(
{"BookCategory": "Action and Adventure"},
{
$set: {
"BookCopies": 2800,
"BookPrice": { $add: ["$BookPrice", 3000] }
}
}
)

var all=db.books.find() .toArray()


printjson (all)
x
(Ertor a
gmail Search xM
-
Aocenture Primer Learning SML X Programming using Python Vacc X
+
û https'accenturelearning tekstaccom/rnod/vpl/forns/edit,php?id=5952&userid=44388# A

File List Save Compile& Run Evaluate Full screen Description

vaccine.py D
1- while True:
2 totalPeople=int (input("Enter the total number of people in the area: "))
3
4 if totalPeople (=8:
5 print ("Invalid input")
6 break
7 sd=int(input("Single-dose count: "))
8 if sd<e or sdototalPeople:
1
11
12
print("Invalid input")
break

dd=int(input ("Double-dose count:: "))


4388
13 if dd<e or dd>totalPeople:
14 print("Invalid input")
15 break
16
17
18
19
2
if sd+dd>totalPeople:
print ("Invalid input")
break
ny=total1People- (sd+dd)
44388
21 vp-(dd/totalPeople) "100
22
23 print("\nNot vaccinated people count:",nv)
24 print("Total vaccinated percentage of people:{: .2f}".format(vp))
25
26 cont=input("\nDo you want to continue (1) for yes (e) for no:")
27
28 if cont '':
29 break
30 elif cont='1':
31 print("Invalid input")
32 break

Breaking news
Unfolding now Q Search ENG
)D
12:47 PM
IN 110/024
Error
a

gmal Search M Accenture Primer Learning-SML X Programming using Python fact X

â htps//accenturelearning. tekstac.com/mod/vpl/loms/edit:php?id=5954&userid=44388# A
accenture Simran Kshatriya

&Dashboard / My courses 7 Python / Control Structures / Eactorial of a number

Practice program: Factorial of a number


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

factorial.py
1 h= int (input ("Enter a number "))
2
3
if n<e:
88
4 print ("Factorial does not exist for negative numbers")
6
else:
7 fact-1
8 for i in range(1, n+1):
10
11
12
fact=facti
print("Factorial is ",fact)
44388

Breaking news ENG 12:47 PM


Unfolding now Q Search IN
)D
1/19/2024
Error gmail- Search x M Accenture Primer Learning - SMU X Progranming using Python BM X

Ô https'accernturelearring tekstaccom/nod/vpl/forns/edit,php?id=59518userid-443884 A

Practice program: BMI Calculator


Description Code Editor Grading view

File List Save Compile & Run Evaluate Fullsureen Description

U
bmi _calculator.py
1 weight=int(input("Enter the weight of the person(kg):"))
2
3 height-float (input (" Enter the height of the person(m):"))
4
5- if weight> and height>0:
6 bmi-(weight/ (height'height))
BMI=round (bmi, 1)
8
9
1€
if BMI>=27.5:
print ("Your
44388
BMI
is "*str(BMI )+" (High Risk)")
11
12 elif BMI>=23 and BMIC=27.4:
print("Your BMI "+str(BMI )+" (Moderate Risk)")
13 is
14
15
-

elif BMI=18.5 and BMI<=22.9:


BMI
OC
16 print("Your is "*str(BMI) (Low Risk)")
17
18 elif BMI(18.5:
19 print ("Your BHI is "+str(BMI) +" (Risk of nutritional deficiency diseases)")
2
21- else:
22 print("Provide a valid input")
File List Save Compile & Run EvalL

userfile.js D
11

3
2
db.employees.updateMany (
{
"DeptNo": "n }, 4388
$set: { "DeptNo": null} }
4 );
5
6 var a = db.employees.find() .pretty();
77 printjson (a);

4438
a
gmail- Search M Accenture Primer Learning- SM
Error

https/accenturelearing tekstaccom/mod/vplorns/edit,php?id=5955&userid=44388#
â
Evaluate Full screen Description
File List Save Compile & Run

armstrong.py D
1 ni, n2= map(int,input ("Enter the starting and ending numbers:\n").split(" "))
2
3- if n1<0 or n2<0:
4 print("Starting and ending numbers must be greater than or equal to zero")
5
6- elif nl>n2:
7 print("Invalid input!
!
Ending number should be greater than starting number")
8
9- else:
10
11
armstrongNo-[] 44388
12 for num in range (n1,n2+1):
13 temp-num
14 sum_cubes=0
15
16 while temp>:
17
18
19
digit-temp%10
sum_cubes+=digit**3
temp//1e
44388
20
21 if sum_cubes==num:
22 armstrongNo. append(num)
23
24 print (f"Armstrong numbers between {n1} and {n2) are: *)
25
26
27
if armstrongNo:
for armstrong in armstrongNo:
print (armstrong)
44388
28 else:
print ("There is no Armstrong number between these numbers")
29

Breaking news ENG 12:48


Unfolding naw Q Search IN 1/19/2
Error gmail- Search xMAcenture Primer Learning-SML X Programming using Python Win x
AN
Ô https/accernturelearning tekstac.com/nod/vpl/foms/editphpid=5956&userid=44388#

Practice program: Window seat or not


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

window_seat.py
1
o388
srow=int(input("Enter the number of seats per row\n"))
2
3- if srow<=0:
4 print("Invalid Input")
5
6- else:
7 sno=int (input ("Enter the seat number\n"))
8
9 if snoc-0 or sno>11"srow:
10 print("Invalid Seat Number")
11
12 else:
% srow =
13 if sno 0:
14 print("Window Seat")
15
16
else:
print("Not a Window
AR88
Seat")
17

62*F
Haze Q Search ENG 1248
File List Save Compile & Run Evaluate Full screen

userfile.js D
i1
2
3
var array=['Python',
db.employees. updateMany(
'DBMS]
4388
4 {"Job" : "Manager"},
:
5 {$push: {"Training_to_Attend" ($each: array}}}
i6 )
7
i8 var training =
db. employees. find("Job" :
"Manager"}).pretty()
i9 printjson(training)
Error Accenture Primer Learming SM X Programming using Python Pass X

û https/laccenturelearning. tekstac.com/nod/vpl/lons/edit php?id=5968&userid-44388#

Practice program: Pass or Fail


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

* exam.py 0
1- def main():
2 subjects=int(input("Enter the no. of subjects: "))
3
if subjects(=0:
4 print("Invalid no. of subjects")
5 else:
6 passed-e
7 failed=e
8 print("Enter the marks: ")
9
10 for i in range (subjects):
11 mark=int (input (0)
12 if mark<e or mark>10e:
13 print ("Invalid mark")
14 exit()
15 if mark>50:
16
17
18
19
else:
passed+=1

failed+=1
44388
2 of subjects passed:",passed)
print("No.
21 print("No. of subjects failed:", failed)
22 return
23
ifname main':
24 main()

ENG 1:0
Breaking news Search IN 1/19
Error Accenture Primer Learning SM X Programming using Python Uni x +

htps/accenturelearningtekstaccom'mod/vollomsjedit phpid=59708userid =44383H A

Dashboard / My courses / Python / Collection Frameworks / Unique and Sorted Words

Practice program: Unique and Sorted Words


Description Code Editor Grading view

File List Seve Compile 8 Run Evaluate Full screen Description

unique.py D

1 string=input("Enter the string:\n")


2
3 l=string. split()
4
5 sortedlist=sorted (set (1),key=str.lower)
6
7 result=' .join (sortedlist)
9
10 print (result)

44388

httos://accenturelearning.tekstac.com/modvol/toms/editphp?id=5970&userid=44388#
1:

Breaking news ENG


nfalding now Q Search IN 1/19
Primer Learning- SML X Programming using Python Ara X
Error gmail Search xMAccenture
û https/accenturelearring.tekstac.com/nod/vp/lorns/edit.php?id=5967&userid=44388#

Practice program: Arrange Names


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

names.py
1
14389R
count=int(input("Enter the number of names:in"))
2
3 name_list-[]
4
5- if count>:
6 print("Enter the names: ")
7 for i in range(count):

1
8
9
name=input()
name_list.append (name)
A388
11 name_list. sort(reverse-True)
12 name_list.sort(key-len,reverse=True)
13
14 print ("The sorted name list is: ")
15 for name in name_list:
16
17- else:
18
print (name)

print("Invalid Input")
44388

62*F
Haze Q Search ENG
IN 1/19
eLeatiig SM Programming using Python Stat: X
X
û httpst/accenturelearning.tekstac.com/mod/vpl/lorms/edit php?id-5972&userid-44388#
A
File List Save Compile & Run Evaluate Full screen Description
* student. _enrollme...0
1- def main():
2 n=int(input ("Enter the no of participants details to be created:"))
3 if n<=:
4 print("Invalid Input")
5 else:
6 student_list-[]
7 if n:
8 for i in range (n):
9
18
11
student=}
name=input("Name: ")
state=input("State: ")
A388
12 age=int (input("Age: "))
13 if age =10 and age>80:
14 print("Invalid Input")
15 continue
16 student [ "Name"]=name
17 student"State"]=state
18 student ["Age"]=age
19 student_list. append (student)
20 print("\niHere's the list of participants details: ")
21 for i in student list:
22 print (i)
23 res={}
24 for i in student list:
if i["State"] not in res.keys():
25
26
27
28
else:
res[i["state"]]=1
res[i["state"]]+=1
44388
29 for key, value in res.items () :
30 print("State: ",key, "Count: ",value )
31 return
32- if name
==main_':
33 main()

Upcoming ENG 1:13 PM


Earnings Q Search IN 1/19/2024
Error Accenture Primer Learning SM X Programming using Python Cre
x+
â https//accenturelearring.tekstaccom/nod/vpl/lons/edit,php?id=59698userid =44388#

Practice program: Create Quarters


Description Code Editor Grading view

File List Save Compile B Run Evaluate Full screen Description

* quarters.py
O2
1 months=('January','February','March', 'April', 'May','June','July', 'August','September','October','November', 'December')
2
3 print("Months in expanded form:")
4- for month in months:
print (month)
6 first-months[:3]
7 second-months[3:6]
9
1e
8 third=months [6:9]
fourth=months [9:] 44388
print ("\nThe four quarters are:")
11 print ("\nFirst Quarter:")
12 for month in first:
13 print (month)
14 print ("\nSecond Quarter:")
15- for month in second:
16 print (month)
17 print("\nThird Quarter:")
18- for month in third:
44388
19 print (month)
20
21 print ("\n Fourth Quarter:")
22- for month in fourth:
23 print (month)

1:3
ENG
Breaking news
Q Search IN 1/19
Eror
M
Accenture Primer Learning SM X Programming using Python No x +

û https//accenturelearning tekstac.com/rmod/vpllorns/edit:.php?id=5976&userid=443884 A

File List Save Compile & Run Evaluate Full screen Description

* doctors.py D
1- def main():
2 def find_not_working_docs(alldoc, workingdoc):
3 not_working_docs-[doctor for doctor in alldoc if doctor not in workingdoc]
4 return not working_docs
5 n1=int (input () )
6 if nl<= 0:
7 print ("Invalid list size")
8 else:
9
10
11
alldoc=[J
for i in range(n1):
docid=int (input())
if docid<=0:
44388
12
13 print("Invalid Id") +
14 break
15 alldoc.append(docid)
16 else:
17
18
19
20
n2=int(input())
if n2<=0:
print("Invalid list size")
44388
else:
21 workingdoc=[]
22 for i in range(n2):
23 docid=int (input(0)
24 if docid<=0:
25
26
27
print("Invalid
break .
workingdoc append (docid)
Id")
44388
28 else:
29 result=find_not_working_docs (alldoc, Workingdoc)
30 print("Not Working Doctors' IDs are:")
31 print('result)
32 return
33- if name=' main':
34 main()
35
62*F ENG 114 PM
Hae
Search IN 1/19/2024
t.melaccenture_updates

Accenture Primer Leaming -SME X


Error M Programming using Python Luch
x+ X

https:/laccenturelearning tekstaccom/mod/vpl/lorms/edit,php?id=5989&userid=44388# A

Practice program: Lucky Number


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

* lucky.py D
3- def main():
4
4388
def find_lucky(num):
sm=0
while numl =0:
temp=num%10
Sm+=temp
num=num//10
10
11
if sm%2=m:
return 1
im44388
12 else:
13 return e
14
number int(input("Enter
15 the number:"))
16 if number <e:
print("Invalid Number")
18
1
26
else:
luckefind_lucky(nunter) 4388
21 if luck=l:
22 print (str(number) +" is lucky")
23 else:
24 print (str (number) +" is not lucky")
29 return
2

62F ENG 117 PM


Haze
Q Search IM V19/2024
t.melaccenture_updates

OError M Accenture Primer Leaming - SME X Programming using Python Disg x + X

à https:t/accenturelearning tekstaccom/mod/vpl/forms/edit.php?id=5991&userid=44388# A

My courses
Dashboard / Python / Eunctions and Modules / Display bars

Practice program: Display bars


Description Code Editor Grading view

File List Compile & Run Evaluate Full screen Description

visualize.py 0 bars.py D init_.pyD


1 ##Do not change the code skeleton given. Write your program in the provided places alone.
2
## Import bars.py
4 inport

6- def main():
bars

### Write your code here


44388
ni=int(input("Enter the no. of times * should display: "))
16 n2=int(input("Enter the no. of times should display: "))
11 n3=int(input("Enter the no. of times ' should display:"))
12
1

14
15
bars.draw_bar(nl,
return
n2, n3))
44388
1

17
18- if _name_=="_main:
19 main()
22

62F 1:18 PM
Haze
Q Search IN V19/2024
t.melaccenture_updates

Error M Accenture Primer Leaning - SME X Programming using Python Resi


x+ X

Ô htps//accenturelearning tekstaccom/mod/vpl/lorms/edit.phpid=5978&userid=44388# A

File List Save Compile & Run Evaluate Full screen Description

D
* resident_info.py
1- def display_residents (residents ):
for . resident in residents:
Drint(resident)
prir
4- def main():
5 n=int (input ("No of Residents: "))
6 if ns=
7 print("Invalid")
return 44388
1e
11
residents=[]
for i in range(1, n+1):
print (f"\nResident {i}:")
44388
12 name=input ("Name: ")
13 age-int (input ("Age :")) +
14
if age<21 or age>58:
15 print(" Invalid")
16 return
:
17 designation=input("Designation
:
")
18 band=input("Band ")
19 if band not in ['A', 'B', "C', 'D']:
20 print("Invalid")
21 return
22 residents.append ((name, age, designation, band))
23
,
print ("( 'NAME', 'AGE' DESIGNATION', 'BAND' )")
24 display_residents (residents)
25 interest_band=input("Enter your band of interest: )upper()
26* if interest_band not in ['A', 'B', 'C', 'D']:
27 print("Invalid")
28 return
29 interest_residents= [resident for resident in residents if resident (3]==interest_band]
3e print ("("NAME', "AGE", DESIGNATION','
BAND')")
31 if not interest_residents:
32 print("No resident under this band")
33 else:
34 display_residents(interest_residents ))
35- if _name_="_main__":
62F 1:16 PM
Haze
Q Search IN 1/19/2024
t.melaccenture_updates

Accenture Primer Leaming -SML


Error M X> Programming using Python Fare x+ X

Ô https:/laccenturelearning tekstaccom/mod/vpl/forms/edit,php?id=5990&userid=44388# A

My courses / Python
Dashbgard / / Functions and Modules Farewell

Practice program: Farewell


Description Code Editor Grading view

File List Compile & Run Evaluate Full screen Description

farewell.py greet.pyD init_.pyD


1 import greet
2
3 name=input ("Enter the senior's name:")
4
5
6
7
print(greet.message, end="
greet.greet(name)
4388
8
9 print("Documentation string:".greet.greet.doc_)

44388

ENG
62F
Haze
Q Search a G0 IN
118 PM
V19/2024
t.melaccenture_updates

OError M Accenture Primer Leaming- SME X Programming using Python Am


X+
à https:t/accenturelearning tekstaccom/mod/vpl/forms/edit.php?id=5994&userid=44388# A
Dashboard / My courses / Python / Eunctions and Modules / Amoeba Mutiplication

Practice program: Amoeba Multiplication


Description Code Editor Grading view

Compile & Run screen


File List
aveS Evaluate Full Description

amoeba.py D

2
3- def fibonacci (month):
4
a, b=0, 1 44388
for ia in range(month-2):
,b=b,a+b
10
11 return
12
13 month=int(input("Enter the month as numeric value:\n"))
14 result=fibonacei(month)
15

16- if monthci or month12:


17 print ("Invalid month")
18- else:
19 print ("The amoeba size is ",result)
26
21
22

ENG
62F
Haze
Q Search aG0 IN
119 PM
V19/2024
t.melaccenture_updates

Accenture Primer Leaming -SME X


Error M Programming using Python Rhyt x+ X

Ô httpsllaccenturelearning.tekstaccom/mod/vpl/Morms/edit, php?id=59928userid=44388# A

File List Save Compile & Run Evaluate Full soreen Description

rhythm.py D
1- def is prime(num):
if num<2:
4 return False
5
6 for i in range(2, int (num**0.5)+1):
7:
if numi--0:
return False
1e
return True
11- def find_prime(start, end):
44388
1
=
prines [nun for num
in range(start, end+1) if is_prime(num) ]
13 return primes +
14
15 start=int (input ())
16 end=int(input())
17
18- if start>end or start<e or end<0:
19
29- ctant Cnvalid range")
elif
44388
21 print ("There are no prime numbers in this range")
22- else:
23 result=find_prime (start, end)
24 if not result:
are no prime numbers in
25
26
27
else:
print("There
print (*result)
this
rne388

ENG
62F 0 119 PM
Haze
Q Search AG IN 1/19/2024
t.melaccenture_updates

Error M Accenture Primer Leaming - SME X Programming using Python Con


x+ X

https:/laccenturelearning tekstaccom/mod/vpl/lorms/edit.php?id=5993&userid=44388# A

Practice program: Concat Strings


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

concat_str.py
O0
4- def concat_string(str1,str2):
your code here and return the values
##rite
=
new_string string1[2:]+string2(2:]
length=len (new_string)

16
11
return nev
string, length88
12
13
14 string1=input (" Enter String1: ")
15 string2=input("Enter String2: ")
16- def main():
17 #** Nrite your code here
18
#stringl=input ("Enter String1:
1c
2€
21
#string2=input("Enter string2:
388
22 result_string, result_length=concat_string(stringl, string2)
23
24 print concatenated string: ", result_string)
("The
25 print ("The length of the new string is : ". result _length)
26
27 return

ENG
62F
Haze
Q Search a G0 IM
119 PM
V19/2024
t.melaccenture_updates

Accenture Primer Leaning -SME


Error M X> Programming using Python Perc x+ X

httpsJlaccenturelearning tekstaccom/mod/vpl/forms/edit.php?id=5995&userid=44388# A
Dashboard / My courses I Pyhon / Eunctions and Modules / Percentage of marks -lambda function

Practice program: Percentage of marks - lambda


function
Description Code Editor Grading view

A4398
File List Save Compile & Run Evaluate Full screen Description

percentage.py 0
1 subject1-float(input("Enter marks for subjecti:"))
2 subject2=float(input ("Enter marks for, subject2:"))
3 subject3=float(input ( "Enter marks for subject3:"))
4
5 cal=lambda s1, s2, s3: (s1+s2+s3) /3
6
7 percentage=cal(subjectl, subject2, subject3)
8
9 print("Percentage is", percentage)

44388

ENG
62F
Haze
Q Search a G0 IN
1.20 PM
V19/2024
t.melaccenture_updates

Accenture Primer Learning -SME X


Error M Programming using Python Bask
x+ X

O https:/iaccenturelearning. tekstaccom/imod/vp/lorms/edit.phpid=5997&userid=44388# A

Dashboard / My courses / ython / Eunctions and Modules I Basket Ball Player Analysis - Numpy aray

-
Practice program: Basket Ball Player Analysis
Numpy array
Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

main.pyD
1 inport numpy as np
2 john_statistics=np. zeros((4,4), dtype=int)
3
4 print(" Enter John's points for each quarter:")
for quarter in range(1,5)
:
5
6 for point in range(1,5):
john_statistics[quarter-1] [point-1]-int (input (f"Quarter {quarter), Point (point}: "))
9 print ("\nJohn's
10 print (john_statistics)
11
Statistics :\
445
1388
12 total_first_two_quarters=np.sum(john_statistics [:2, :])
13
14 average _last_quarter=np.mean(john _statistics [3, :])
15 print ("\nTotal points scored by John in the first 2 quarters : {:.2f}".format (total_first_two quarters))
16 print ("Average points scored by John in the quarter: {:.2f}".format(average_last_quarter))

62F 0 ENG 1.20 PM


Haze
Q Search A IN V19/2024
t.melaccenture_updates

Accenture Primer Leaming -SME X


Error M Programming using Python Fun x+ X

Ô https:/iaccenturelearning. tekstaccom/mod/vp/lorms/edit.phpžid=5996&userid=44388# A

Dashbgard / My courses / Python / Functions and Modules / Funny String

Practice program: Funny String


Description Code Editor Grading view

File List Compile & Run Evaluate Full screen Description

funny.py 0
1- def funny_string(s) :

2
if len(s) <2 or len(s) >5e:
return "Invalid string"
reverse_s=s[::-1]
388
8 for i in range(1,len(s)):
9 if abs(ord(s[i])-ord(s[i-1]) ) = abs(ord(reverse_s[i]) -ord (reverse_s[i-1])):
10 return "Not Funny"
11
12 return "Funny"
1:
14
15
input_string=input ("Enter the the8
16 result=funny_string(input_string)
17 print (result)

62F ENG 120 PM


Haze
Q Search A R0 IM V19/2024
t.melaccenture_updates

Error M Accenture Primer Leaming - SME X Programming using Python 1Dt


x+ X

Ô htps/laccenturelearning tekstaccom/mod/vpl/lorms/edit.phpid=5998&userid=44388# A

File List Save Compile & Run Evaluate Full sercen Description

main.pyD
1 import numpy as np

3 pixe values=[]
4 printt"Enter pixel values for the inage (8 values) :")
5- for i in range(1, 9) :
6 value=int (input (f"Pixel {i}: "))
7:
while value>256 or value<e:
print("Invalid input! Enter a value between and 256")

1e
11
12 image_matrix
value=int(input
pixel_values
.

=
("Pixel (i}:
append (value) ;338
np.array (pixel_values). reshape (2,4)
13 +
14 print("\nOriginal Array: \n")
15 print (np. array(pixel_values))
16
17
18
19
print ("\nImage Matrix (2x4)
print (image_matrix)
:\n")
44388
20 top_1eft_region= image_matrix[ :1, :2)
21 bottom_right_region= image_matrix[1:, 2:]
22 mean_value=np.mean(image_matrix)
23
24 print("\nTop-left 2x2 Region: \n")
25
26
27
28
print (top_left_region)
print("\nBottom-right 2x2 Region:\n")
44388
print(bottom_ right_region)
29
30 print("\nMean value of the pixel values in the image Matrix: {:.2f}".format (mean_value))

62-F A
ENG 121 PM
Haze
Q Search IN 1/19/2024
t.melaccenture_updates

( Error M Accenture Primer Learning- SM x > Programming using Python Find


x+ X

û httpst/accenturelearning.tekstac.com/mod/vp/lorns/editphp?id-6016&userid=44388# A

-
Dashboard / My courses / Python / Code Analysis and Debugging / Find Sum Code Analysis

Practice program: Find Sum -Code Analysis


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

main.pyD
1- def main():
print ("Enter the value of N")

5
number=int(input ())
Sm=0
if number<e:
44388
6 print("Invalid input")
7 else:
for i in range(1,number+1) :
Sm=sm+i
10
sum
11 print (f"The of first (number} natural numbers is (sm}")
12
13
14
15- if__name_"_main_":
16 main()
17

62*E ENG 122 PM


Q Search
Haze L 1/19/2024
t.melaccenture_updates

( Error M Accenture Primer Leaning SML


X> Programming using Python Aute x + X

Ô httpst/accenturelearning.tekstac.com/mod/vpl/lorns/edit.php?id=6018&userid=44388# A

File List Save Compile & Run Evaluate Full screen Description

* main.py
1 # Function to check Odd number
2- def checkodd (N):
NS2 l se:
if
return True
5 else:
6 return False
Function to check Automorphic number
#
7
:
8- def isAutomorphic (N)
10
11
sq = NN
while (N ) :
if N% 10
>

= sq %
10
44388
:
12 return False
13 N
// 10
14 sq //= 10
1
return True
16 # Driver method
17- def main():
18
19
print("Enter
N=int(input ())
the number:") 44388
20
:
21 if checkOdd (N)
22 if isAutomorphic(N):
23 print("Automorphic Number")
:
24 else
("Not an Automorphic Number")
25
26
27
else:
print("Not
print

main":
an Odd Number") 44388
28- if name"
29 main()
3e
B1

62*F ENG 123 PM


Q Search
Haze 1/19/2024
t.melaccenture_updates

( Error M Accenture Prímer Leaning SMU X Programming using Python Wea


x+ X

û httpsd/accenturelearning.tekstac.com/mod/vpl/forns/edit.php?id=59998userid=44388# A

File List Save Compile & Run Evaluate Full screen Description

main.pyD
1 import numpy as np
num days=int (input ("Enter the number of days: "))

5 print (" Enter temperature records for ", num_days, " days:")
6 temperatures= np. zeros (num_days, dtype-float)
7- for day in range (1, num_days+1):
temperatures[day-1)=float(input (f"Day (day}: "))
18 print ("\nTemperature Records for the City:\n")
11 print (temperatures)
12
13 mean _temp=np.mean (temperatures)
14
15 maxtemp_index=np. argmax (temperatures)
16 maxtemp_day=maxtemp_index+1
17 maxtemp_value-temperatures
18
[maxtemp_index]

19 mintempAndex=npP.argmin(temperatures)
20 mintemp_day=mintemp_i
44388
21 mintemp_value=temperatures [mintemp_index]
22
23 sindices=np.argsort (temperatures)
24 sdays=sindices+1
25
26
27
stemps=temperatures [sindices]
44388
print ("\nMean Temperature for ", num_days, " Days: {:.2f)}.format (mean_temp))
28 print (f"Day with the Highest Temperature: Day (maxtemp_day) Temperature: (maxtemp_value)")
29 print (f"Day with the Lowest Temperature: Day (mintemp_day) Temperature: {mintemp_value}\n")
30
31 print ("Days Sorted by Temperature (Ascending Order):\n")
32
33- for day, temp in zip(sdays, stemps):
34 print(f"Day (day}: Temperature (temp}")

62*E ENG 121 PM


Q Search
Haze 1/19/2024
t.melaccenture_updates

( Error M Accenture Primer Learning-SMU X> Programming using Python Tale


x+ X

â httpst/accenturelearning.tekstac.com/mod/vpl/lorms/edit.php?id=60208userid=44388# A
Q
Dashboard / My courses / Python / Code Analysis and Debugging / Talent Search Test - Files

Practice program: Talent Search Test - Files


Description Code Editor Grading view

File List Compile & Run Evaluate Full screen Description

marks.py U
1 name
list-[]

4- with open('student _marks.txt',"r) as


student_list-file obi.readlines()

8- for i in range(e, len (student list),2):


>
9 if int(student _list[i+1] ) =80:
12 name_list.append(student_list[i])
11
12
13- for
14
i in
print(i)
name
list: 44388
15
16

62*E ENG 124 PM


Haze
Q Search L IN 1/19/2024
t.melaccenture_updates

( Error M Accenture Primer Learning SM


X> Programming using Python List x + X

â httpst/accenturelearningtekstac.commod/vpl/lorrns/edit.php?id=6019&userid=44388# A

Practice program: List of Lists


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

main.py 44388
1- def operation (my list):
mx-float('-inf')
for i in mylist:
5 for i in i:
6 sm=j
7
if j>mx
:

mx=j 44388
1
11 return mx, sm
1
13
## print (len (mylist))
y_list-([3,5,6], [7,8, 44]
14
15
16
17
valuel, value2=operation
print(valuel,"
"
(my_list) .B88
is the Maximum value")
e

18 print(value2, is the sum")


19

62*E 124 PM
Haze
Q Search AR 0 ENG
1/19/2024
t.melaccenture_updates

(Error M Accenture Primer Learning- SMU


X> Programming using Python Su
x+ X

û httpsl/accentureearning. tekstac.com/mod/vpl/lorns/edit,php?id=6017&userid=44388# A

& Dashboard / My courses / Python / Code Analysis and Debugging / Sum the Odd and Even

Practice program: Sum the dd and Even


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

oddeven.py
1- def operation (my_tuple):
2 even_ sum-0
odd sum-e
for i in my_tuple:
if i%2==0:
44388
even s
um+=i
7:
else:
8 odd_sum+=i

1e return even_sum, odd_sum


11
12
13 my_tuple-(20,5, 70,9,18ee)
44388
14 sum_value-operation (my_tuple)
15
16 print ("Sum of odd numbers:", sum_value[1])
17 print ("Sum of even numbers:", sum_value[e])

62*E ENG 122 PM


Q Search
Haze 1/19/2024
Practice program: Courier Count
Description 51 Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

sample.sql
1 SELECT Contact_no, cOUNT( ) AS COURIER COUNT
FROM Courier
3 GROUP BY Contact no
>
4
HAVING COUNT () no
1
5 order BY Contact ASC;

50882
Practice program: Customer Contact
Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

sample.sql
1 select
as
Customer_name,customer Address, coalesce(Email, To_char (Contact_no))
2as from
Contact Customer
3
where INSTR(SUBSTR(Customer_Address, 5,1),'')>e
4 order by Customer_name desc;

50882

KAG

S8P 500 Q Sesrch


Practice program: Couriers Delivered On Same Date

Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

sample.sql
1 Select 50982
c1.Courier ID as Courierl,
c2.Courier ID as Courier2,as
Actual Delivery date
4 c2.Actual Delivered_date
from Courier status c1 on c1.Actual_Delivered_date = c2.Actual_Delivered_date
6 join Courier status

9
7

8 order
AND c1.Courier Ibc2.Cour

by
c2.Actual_Delivered_dete rie882
desc

10c1.Courier ID desc;
exam,py D

aDo not change the code skeleton given. your progean in the provided places alone
irite
def main():
Write your code here
word dict {)
while True:
word=ingut(' Enter the
no_of
ofdih)Q
meaningsint (input('Entar the no of meanings:\n'))
Simple word dictionary
no of
11 if meaningsce:
12 pránt(Ihvalid Input)
13
far key, value in word_dict.items():
rint(f(key):(value))
break
17

19
eiselmeaningsa[1
print("Enter the meanings:)
50882
for i in range(no_of_meanings):
eanings, append (data)
word dict [word]=meanings
press
mare elenants to the dictionary? If yes, press 1, else
8:

choiceint(input ('Do you want to add onée more


25
26
27 if choicerel:
28 continue
petnt("Here's the dictionary you"ve created:)
in word dict.items():
for key,value(key}:(value)")
print(f"
break
4
O Seatch
14 for key,value in word_dict.items():
15
16
print(f(key}:(value)')
tbreak
Blse:
meaningS=[]
P
Enter the meanings:)
(no_of meanings):
27 datainput()
meanings.append(data)82 Simple word dictionary
28 word_dict [word]ameanings
24
25 choice=int(input('Do you want to add one more elements to the dictíonary? If yes, press 1, else press 0:\
26
1f choices1:
e1if
print("Here's the dictionary you've created:")
for key, value in Word dict.items( ):
32 print(f'(key}:{value)")?
33 break
else:
35 print('Invalid Input")
36 print (Here's the dictionary you' ve created:")
37 for key,value in word_dict.itemsC
break
print(f{key):(value)") 050882
4e return
42
4:
44- if
4
_namemain
main()
46

Q
Search
File List Cormpile & Run Evaluate Description

courses.py
1 no
of cs
int(input('Enter the number of courses:\n'))
2 subjects, marks = ).
3- 1f no of_cs<1:
print(Invalid no. of courses)
quit()
6else:
for i in range(no_of_cs):
8 print('Enter the name of the subject and marks respectively:')
1
e0882
datal=ir
data2-int (input ("\n')
if data2ce or data2>100: Aeimas online course
print("Invalid mark')
quit()
4 else
subjects. append (data1)
marks. append (data2)
50882
L6

18 print('The courses you have cleared are:")


19
20 for i in range(no_of_cs):
21 if marks[i]>=80:
22 print(f'(subjects[3]) (marks[i]}' )
23

50882
Practice program: Password Protection
Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

password.py 0

1 total_ plots
=
int (input('Enter the total no.of plots:\n')
2- if total_ plots<1 or total_plots>20:
3 print(" Invalid Input')
4 quit()
5 plots=[]
6 print('Enter the numbens of each plot:')
7- for i in range (total plots):
8 plot=float (input 0)
9 if plot=e: Invalid Input')
10 print("
11 quit()
12 plots. append (plot)
13
sum( [i for i in plots if i%2l=0])
14 odd_sum
even_sum = sum([i for i in plots if i%2-0]
15
sum+even_sum) /2
16 average
= (odd
17 print (f' The password for the file is: (average:.2f}')
7
Eieanalibg/ Siore StudentData

Practice program: Store Student Data


Description
50Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

sample.py D
1 no = int(input (' Enter number of
, students: \n"))
2 file open('output_data.txt' 'w')
3- for i in range(1, no+1):

4 print (f'For student (i}')


5 name=input('Enter name: \n')
score=int(input ('Enter the score: n'))
7 data_format=f'Name: (name) Score: (score)"
8 file.write(f' (data_format} \n')87
9 file.close()
10 read file=open('output_data.txt,'r)
11 data=read file.read()
12 print('" \noutput_data.txt will contain:')
13 print (data)
14 read_file.close()
& Dashboard / My courses / ython/ Eile Handling / Read CSV file

Practice program: Read CSV file


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

read csv.py
1 import csv
2
50892
open('0neDayInternational.csv',r')as csv_file:
3-with csV_reader=csv.DictReader (csv_file)
5 count-
t-0
6 for row in csv_reader:
print (row)

9
16
8 count+=1
if count=10:
break
50882.
Dashboard / My courses/Python / Eile Handling / Copy the File

Practice program: Copy the File


Description Code Editor Grading view

File List Save Compile & Run Evaluate Full screen Description

filecopy.py D
1- with open(file_in.txt',')as input_file:
2 with open("file out.txt', 'w)as output file:
3 for line in input_file:
4 output_file.write (line)

6- with open('file_out.txt', 'r')as output_file:


print(output_file.read())
7
50882
Practice program: Filter the Countries Sachin has
Played Against - CSV file
Description Code Editor Grading view

Compile & Run Evaluate Full screen Description


File List Save

FilterCountries.py0
import csv
1

3- with open('OneDayInternational.csv','r')as csv_file:


csv.DictReader(csv_file)
4
5
6
cSV_reader
countries=set()
for row in csV. reader:
50832.
7 countries add (row['Versus'1)
8 countries=sorted (countries)
9 print(countries)
Dashboard / My courses/ Python/Eile Handling / Calculate year-wise totalnumber of runs of Sachin

Practice program: Calculate year-wise total number


of runs of Sachin
Deseription Code Editor Grading view
500
File List Save Compile & Run Evaluate Full screen Description

AddColumns.py D
1

3
import csv
year_runs={}
50882
4- with open('0neDayInternational.csv', 'r)as csv_file:
5 csV_readerscs.DictReader(csv_file)
6 for rOw in csv reader:
7
year=rowE'MatchDate'].split("/)[21
runs=int(row['Runs']) +runs
8
year runs[year]=year_runs.get (year,0)
10 sorted(year_runs.items ()):
11 for year, runs in
12 print(year, runs)

ENG

L
Q Search
79F
tekstccOVmodpyios/edit:php?ikd=6013&userid-s0882H

File List Compile & Run Evaluate Description

loan.pyD
1 inport json
2
3- def filter_customers(loantype):
4 with open('loan.json' )as json_file:
5 data=json.load(json_file)
6 Customers=data['customers
cOuntee

10
8 for customer in customers:
loans=customer
for loan in loans:
oans)82 JSON file
11 if loantloan type'].lower()==loan type:
72 countt1
13 if count=-0:
14 print('No customers available)
15 else:
16 print('Loan Details')
17 print("Account_Number\tCustomer_Name tLoan Amount

18 for customer in customers:


19 loans=customer[loans]
20 for loan in loans: type:
21 if loan['loan_type'].lower()==1loan
print(customer['Account_Number'1'\t", customer['customer_name'], "\t',loan'loan_
amount'])
22
23 loan type-input('Enter the loan type\n)
24 filter_customers (loan_type)
50882

You might also like