Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

Python - Lists, Tuples, Dictionaries practice tests with solutions

Beoordeling
-
Verkocht
-
Pagina's
13
Cijfer
A+
Geüpload op
04-11-2021
Geschreven in
2021/2022

This document contains all the exam questions with solutions related to Functions in Lists, Tuples and Dictionaries in the python coding language **Its recommended to solve the questions first and then compare with the official solutions.**

Meer zien Lees minder
Instelling
Vak

Voorbeeld van de inhoud

FUNCTIONS AND LISTS

Problem Definition :
Define functions:
• REPLACE(L,N) – this function takes a list L containing integers and an
integer N as parameters and increases the value of all odd elements by N and
decreases the value of all even elements by N.
• EXCHANGE(L) – this function takes a list L containing integers and
exchanges the first half elements of the list with the second half. ( Note : - if
the list has 6 elements then exchange first 3 elements with the last 3
elements and in case the list has 7 elements then exchange first 3 elements
with the last 3 elements leaving the middle element untouched.)
Both the functions will not display the list but only perform the task

Write a menu driven program in python which displays a menu to the user and
depending upon the user’s choice invokes the above mentioned functions and
displays the modified list.

PROGRAM CODE:

def replace(l,n):
for i in l:
if i%2==1:
i+=n
else:
i-=n
print(i)

def exchange(l):
mid=len(l)//2
for i in range(0,mid):
l[i],l[mid+i]= l[mid+i],l[i]
print(l)

, while True:
print("""MENU:
1.ADD ODD AND SUBTRACT EVEN
2.REPLACES FIRST HALF WITH SECOND HALF
3.EXIT""")

ch=int(input('enter choice'))
if ch==1:
l=eval(input("Enter elements of ure choice"))
n=int(input("Enter even or odd"))
replace(l,n)
elif ch==2:
l=eval(input("Enter elements of ure choice"))
exchange(l)
elif ch==3:
break
print()


O/P:

MENU:
1.ADD ODD AND SUBTRACT EVEN
2.REPLACES FIRST HALF WITH SECOND HALF
3.EXIT

enter choice1

Enter elements of ure choice[5,9,6,7,2,6,4]

Enter even or odd9
-5

MENU:

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
4 november 2021
Aantal pagina's
13
Geschreven in
2021/2022
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$5.99
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
Stevendurby

Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
Stevendurby Vellore Institute of Technlogy
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
4 jaar
Aantal volgers
0
Documenten
6
Laatst verkocht
-

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen