Take a look at the code examples below and see if you can figure out what the code will do and what the output will be.
NOTE: These programs do not give very good prompts and outputs and comments - in a normal program, you would want to make sure to always give detailed prompts, outputs and comments. They are missing in these programs so that you are not given any clues as to what the program does.
# Program 1
name = input()
while not name.isalpha():
name = input()
print(name.capitalize())
# Program 2
count = 0
sentence = input()
for letter in sentence:
if letter in "aAeEiIoOuU":
count = count + 1
print(count)
# Program 3
letter = input()
word = "antidisestablishmentarianism"
for char in word:
if char == letter:
print(char)
# Program 4
letter1 = input()
letter2 = input()
while letter2 == letter1:
letter2 = input()
alpha = "AbCdefGHiJKLmnoPqRsTUvwxyZ"
location1 = alpha.find(letter1.lower())
location2 = alpha.find(letter2.lower())
if location1 == -1:
letter1 = letter1.upper()
else:
letter1 = letter1.lower()
if location2 == -1:
letter2 = letter2.upper()
else:
letter2 = letter2.lower()
alpha = alpha.replace(letter1, letter2)
print(alpha)
Answers
Answered by
2
Answer:
You are using Python Good
Explanation:
You can use Python Validator Online
https://extendsclass.com/python-tester.html
It will check your program plz rate if it was helpful to you ,
Answered by
11
Given below are the interpretation of the given programs.
Explanation:
- First program takes a string input checks if its an alphabetical string or not. If its not it asks for the input again until it gets a true alphabetical string. Finally, it prints the input alphabetical string by capitalizing its first letter.
- Second program takes a string input and runs under a for loop to count the number vowels present in it and print the the count as its output.
- Third program takes string input in variable 'letter' and runs a for loop in the given word and checks for common character between this 'letter' and the word and immediately prints the common character.
- Fourth program takes two character inputs. Checks if they are equal or not , if yes it asks for one input more. Then it checks for both the letter's presence in the given string 'alpha'. If they are not present in alpha the letters are converted to uppercase and if they are present it changes them to lowercase. It then inter changes both letters in the string alpha and prints it.
Similar questions