-



Download 9,79 Mb.
Pdf ko'rish
bet36/64
Sana16.01.2022
Hajmi9,79 Mb.
#372467
1   ...   32   33   34   35   36   37   38   39   ...   64
Bog'liq
[Nichola Lacey] Python by Example Learning to Pro(1)

if msg.isupper(): 
 print(“Uppercase”) 
else: 
 print(“This is not in uppercase”) 
If the message is in uppercase it will display the message 
“Uppercase”, otherwise it will display the message “This 
is not in uppercase”. 
msg.islower() 
Can be used in place of 
the isupper () function 
to check if the variable 
contains lower case 
letters.  
msg=”Hello” 
for letter in msg: 
 print(letter,end=”*”) 
Displays the message, and between each character it will display a “*”. 
The output in this example will be: 
H*e*l*l*o* 
Remember, you can always 
look back on previous 
programs to remind 
yourself of the skills learnt 
earlier. 


Challenges 80 - 87: More String Manipulation 
669 
 
 
 
Challenges 
 
 
 
 
 
 
 
 
 
 
 
080 
 
Ask the user to enter their 
first name and then display 
the length of their first name. 
Then ask for their surname 
and display the length of 
their surname. Join their first 
name and surname together 
with a space between and 
display the result. Finally, 
display the length of their full 
name (including the space). 
081 
 
Ask the user to type in their favourite school subject. 
Display it with “-” after each letter, e.g. S-p-a-n-i-s-h-. 
082 
 
Show the user a line of text from your favourite poem 
and ask for a starting and ending point. Display the 
characters between those two points. 
083 
 
Ask the user to type in a word in upper case. If they 
type it in lower case, ask them to try again. Keep 
repeating this until they type in a message all in 
uppercase. 
084 
 
Ask the user to type in their 
postcode. Display the first 
two letters in uppercase. 
085 
 
Ask the user to type in their name 
and then tell them how many vowels 
are in their name. 
086 
 
Ask the user to enter a new password. Ask 
them to enter it again. If the two passwords 
match, display “Thank you”. If the letters are 
correct but in the wrong case, display the 
message “They must be in the same case”, 
otherwise display the message “Incorrect”. 
087 
 
Ask the user to type in a word and then 
display it backwards on separate lines. For 
instance, if they type in “Hello” it should 
display as shown below: 
 


770 
 
Challenges 80 - 87: More String Manipulation 
 
 
Answers 
0080 
 
081 
 
082 
 
083 
 
084 
 


Challenges 80 - 87: More String Manipulation 
771 
 
 
 
0085 
 
086 
 
087 
 
 
 


772 
 
Challenges 88 - 95: Numeric Arrays 
 
 
Challenges 88 - 95 
Numeric Arrays 
Explanation 
Earlier in the book we looked at lists (see page 58). Lists can store a jumble of different types 
of data at the same time, including strings and numbers. Python 
arrays
 are similar to 
lists, but they are 
only used to store numbers
. Numbers can have varying ranges, but 
in an array all pieces of data in that array 
must have the same data type,
 as outlined 
in the table below. 
T
Type code 
 
C
Common name 
 
D
Description 
 
S
Size in bytes 
 

Download 9,79 Mb.

Do'stlaringiz bilan baham:
1   ...   32   33   34   35   36   37   38   39   ...   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