Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools


participate  in  the  upcoming  campus  queen.  Once  we  verify  their



Download 2,02 Mb.
Pdf ko'rish
bet107/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   103   104   105   106   107   108   109   110   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with


participate  in  the  upcoming  campus  queen.  Once  we  verify  their
registration,  we  can  transfer  them  to  the  list  of  registered  students.  To  do
this, we can use a while loop test to move users from our unapproved lists
to approved lists. Let us see how the code will be:
#starts with students that should be approved,
# and an empty list to store approved students
unapproved_student = [“Moses,” “Sarah,” “Abigail,” “Benson”]
approved_student = []


#check if the user pending when there are no more unapproved students
#transfer each approved students to the approved list.
while unapproved_student:
user = unapproved_student.pop()
print(f “Checking student: {user.title()}”)
approved_student.apend(user)
#Prints all the list of approved student
print(“\nThe following students have been approved:”
for approved_students in approved_student:
print(approved.title))
Let  us  analyze  the  program  before  giving  a  sample  of  the  output.  We
declare  a  variable  unapproved_student  with  values  as  Moses,  Sarah,
Abigail,  and  Benson.  Then  we  also  declared  another  variable  as
approved_student  but  with  an  empty  list.  furthermore,  we  use  the  while
loop, which runs as far as our unapproved_student list isn’t empty. Insider
the  loop,  we  use  the  pop()  function,  which  removes  any
unapproved_student starting from the end of the list.
Here, because Benson is the last name in our unapproved_student list, his
name  will  be  taken  off  from  the  list  before  assigned  to  a  user  before  it  is
added  to  our  approved  list.  Then  it  will  go  back  to  the  while  loop  and
continue the process from Abigail, to Sarah and finally to Moses.
We  check  each  student  to  ascertain  their  approval  statues  before  adding
them  to  our  list  of  approved  students.  As  the  unapproved  student  list
decreases,  so  does,  the  approved  list  increases.  However,  once  the
unapproved  student  list  becomes  empty,  the  loop  stops  and  the  approved
student list is printed. Let us check our output:
Checking student: Benson


Checking Student: Abigail
Checking Student: Sarah
Checking Student: Moses
The following students have been approved:
Benson
Abigail
Sarah
Moses

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   103   104   105   106   107   108   109   110   ...   126




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish