CS 1101-01 Unit 5
CS 1101-01 Unit 5
Sarah Hauya
To preamble, this Programming assignment will answer the folliwing given problem;
Write program to display your name and perform following operations on it:
3. Reverse it.
The code and its output must be explained technically. The explanation can be provided before or
after the code, or in the form of comments within the code. The descriptive part of your response
must be at least 200 words.
n = int (input ("Enter the number of characters to display from left: "))
The program will begin by asking the user to enter his/her name using the input() function and will keep
it in variable called my_name. The user will be instructed to enter the number of characters he like to
print from the left side by using the input() function and converts it into an integer by using the int()
function. This value will be stored in the variable n.For displaying the characters starting from Left, the
program will use slicing with my_name[:n] andit will return a substring which contains the first n
characters of the my_name. The result will bestored in the variable named left and will be printed.
count = 0
count += 1
Explanation to above;
In order to count the number of vowels, the program initialises a variable named count to 0. By using a
forloop, it will iterate upon every character in variable my_name which was used in first part of the
program. For instance, If the program finds the lowercase version of the character is found, count
variable is incremented by 1. Then the program will print the value of count.
Number of vowels: 3.
For this section of assignment, this program will use slicing with the variable my_name[::-1] syntax; this
will return a reversed model of it. The result will be stored in the r_name variable and it will be finally
printed.
Conclusion
Above are explanations and solutions to the given problems in this week 5 Programming assignment
part.