54.7k views
0 votes
Write a loop that computes and displays the sum of the Unicode values of the characters in a string variable named name. Provide your own string to store in name. Create a string called movie and store the title of a movie in it. Pick a movie whose title contains at least 5 characters. Using a for-loop and an if-statement, count and display the number of lowercase vowels in the movie title. (Hint: suppose ch stores a particular character from a string. The Boolean condition ch in 'aeiou' evaluates to True when ch stores a vowel.)

User Gsm
by
7.9k points

1 Answer

2 votes

Answer:

For the "Name" variable

name = "Hello, sunshine!"

total_unicode_sum = 0

for char in name:

total_unicode_sum += ord(char)

print(total_unicode_sum)

For the "movie" variable

movie = "The Lion King"

count = 0

for char in movie:

if char in 'aeiou' and char.islower():

count += 1

print(count)

[Note: With this code, a for loop is used to repeatedly traverse through each character in the movie string. If the character is a lowercase vowel, we utilize an if statement to determine whether to increase the count variable. In order to show the quantity of lowercase vowels in the movie title, we output the value of count.]

Bonus:
Here is combined code that would work as an executable.

name = "Hello, world!"

total_unicode_sum = 0

for char in name:

total_unicode_sum += ord(char)

print("The total Unicode sum of the characters in", name, "is:", total_unicode_sum)

movie = "The Lion King"

count = 0

for char in movie:

if char in 'aeiou' and char.islower():

count += 1

print("The number of lowercase vowels in", movie, "is:", count)

[Note: The for loop and ord() method are used in this code to first get the name string's overall Unicode sum. The complete Unicode sum and a message are then printed.

The code then used a for loop and an if statement to count the amount of lowercase vowels in the movie text. Following that, a message and the count are printed.

When you run this code, it will first show the name string's character count in total Unicode, followed by the movie string's number of lowercase vowels.]

User Baach
by
8.4k points