-


party and then display how many people they have



Download 9,79 Mb.
Pdf ko'rish
bet24/64
Sana16.01.2022
Hajmi9,79 Mb.
#372467
1   ...   20   21   22   23   24   25   26   27   ...   64
Bog'liq
[Nichola Lacey] Python by Example Learning to Pro(1)


party and then display how many people they have 
coming to the party. 
049 
 
Create a variable called 
compnum and set the value 
to 50. Ask the user to enter a 
number. While their guess 
is not the same as the 
compnum value, tell them if 
their guess is too low or too 
high and ask them to have 
another guess. If they enter 
the same value as 
compnum, display the 
message “Well done, you 
took [count] attempts”. 
050 
 
Ask the user to enter a number between 
10 and 20. If they enter a value under 10, 
display the message “Too low” and ask 
them to try again. If they enter a value 
above 20, display the message “Too high” 
and ask them to try again. Keep repeating 
this until they enter a value that is 
between 10 and 20 and then display the 
message “Thank you”. 
051 
 
Using the song “10 green bottles”, display the lines “There are [num] green bottles 
hanging on the wall, [num] green bottles hanging on the wall, and if 1 green bottle 
should accidentally fall”. Then ask the question “how many green bottles will be 
hanging on the wall?” If the user answers correctly, display the message “There will be 
[num] green bottles hanging on the wall”. If they answer incorrectly, display the 
message “No, try again” until they get it right. When the number of green bottles gets 
down to 0, display the message “There are no more green bottles hanging on the wall”. 


Challenges 45 - 51: While Loop 
443 
 
 
 
Answers 
0045 
 
046 
 
047 
 
048 
 
049 
 


444 
 
Challenges 45 - 51: While Loop 
 
 
0050 
 
051 
 
 
 
 
 


Challenges 52 - 59: Random 
445 
 
 
 
Challenges 52 - 59 
Random 
Explanation 
Python can generate 
random
 values. In reality, the values are not 
completely random as no computer can cope with that; instead it uses an 
incredibly complex algorithm that makes it virtually impossible to accurately 
predict its outcome so, in effect, it acts like a random function. 
There are two types of random value that we will be looking at: 
x
 
Random numbers within a specified range;  
x
 
A random choice from a range of items that are input. 
To use these two options, you will need to import the random library. You do 
this by typing 

Download 9,79 Mb.

Do'stlaringiz bilan baham:
1   ...   20   21   22   23   24   25   26   27   ...   64




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