Question

Write a program(Python language for the following three questions), with comments, to do the following:   ...

  1. Write a program(Python language for the following three questions), with comments, to do the following:   
    1. Ask the user to enter an alphabetic string and assign the input to a variable str1. Print str1.
    2. Check if str1 is valid, i.e. consists of only alphabetic characters. If str1 is valid
      1. Print “<str1> is a valid string.”
      2. If the first character of str1 is uppercase, print the entire string in uppercase, with a suitable message.
      3. If the first character of str1 is lowercase, print the entire string in lowercase, with a suitable message.

         otherwise (i.e. str1 is not an alphabetic string) print a message saying that the user entered an invalid input.

    1. Print str1 centered in a field of 25 characters, with ‘#’ used as padding. Part c should be done, whether str1 is a valid string or not.
  1. Write a program, with comments, to do the following:   
    1. Ask the user to enter an alphabetic string str1 with only uppercase letters. You may assume the user will enter valid string. Print str1.
      1. If the first 2 characters of str1 are in the range A – HM, print “<str1> belongs to group 1.”
      2. If the first 2 characters of str1 are in the range HN – KI, print “<str1> belongs to group 2.”
      3. If the first 2 characters of str1 are in the range KJ – TZ, print “<str1> belongs to group 3.”.
      4. Otherwise, print “<str1> belongs to group 4.”.

   3.Write a program, with comments, to do the following:

  1. Define a list L1 consisting of at least 5 strings (e.g. L1 = [‘apple’, ‘ball’, ‘camera’, ‘dog’, ‘elephant’, ‘flower’, ‘go’]) and print L1.
  2. Ask the user to enter an integer n between 0 and max-1, where max is the number of elements in the list. Assume user will enter an integer, but it may not be in the proper range.
  3. Check if n is in the proper range. If n is in proper range:
    1. Assign nth element of L1 (e. element with index n) to variable x. Print x with a suitable message.
    2. Check if last character of x is a vowel.
      1. If it is a vowel, print x in uppercase.
      2. Otherwise, print the number of characters in x with a suitable message.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1)ans..

str1 = input("Enter string : ") #Read input
str2=str1 #assign it to str2
if(str1.isalpha()): #check if it contains only aplphabets or not
print(str1," is valid")
if(str1[0].isupper()): #echck if first is capital or not
print(str1.upper())
elif(str1[0].islower()): #check if second char is lower case or not
print(str1.lower())
else:
print("you entered a invalid input")
else:
print("you entered a invalid input")

print(str1.center(25,'#'))

OUTPUT:

Q2)ANS

CODE:

str1 = input("Enter string in UPPERCASE : ")
if((str1[0]>='A' and str1[0]<='H')and (str1[1]>='A' and str1[1]<='M')):
print("belongs to group 1")
elif((str1[0]>='H' and str1[0]<='K')and (str1[1]>='I' and str1[1]<='N')):
print("belongs to group 2")
elif((str1[0]>='K' and str1[0]<='T')and (str1[1]>='J' and str1[1]<='Z')):
print("belongs to group 3")
else:
print("belongs to group 4")

OUTPUT:

Q3)ANS

CODE:

L1 = ['apple','ball','camera','dog','elephant','flower','go']
vowel="aeiou"
n = int(input("Enter n value : "))
if(n>=0 and n<=len(L1)-1):
x=L1[n]
print("Elements at",n," is",x)
if(x[len(x)-1] in vowel):
print(x.upper())
else:
print("Number of characters in",x ," is",len(x))
else:
print("out of range ")

OUTPUT::

If you have any doubts please COMMENT..

If you understand the answer please give THUMBS UP...

Add a comment
Know the answer?
Add Answer to:
Write a program(Python language for the following three questions), with comments, to do the following:   ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Python program, with comments, to do the following:                        Ask the user to enter...

    Write a Python program, with comments, to do the following:                        Ask the user to enter a string with at least 7 characters. Assume user will enter a valid string. Assign the string to a variable str1 and print str1. In a loop do the following: Update the value of str1 so that the first character from the current value of str1 is removed and added to the end. Print the updated str1.       The loop should continue until updated...

  • 2. Searching a String: Write a MIPS assembly language program to do the following: Read a...

    2. Searching a String: Write a MIPS assembly language program to do the following: Read a string and store it in memory. Limit the string length to 100 characters. Then, ask the user to enter a character. Search and count the number of occurrences of the character in the string. The search is not case sensitive. Lowercase and uppercase letters should be equal. Then ask the user to enter a string of two characters. Search and count the number of...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Your assignment is to write an assembly language program which read a string and print it in...

    Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the user to enter a string which is subsequently displayed in uppercase. It is important to first ensure that string to be converted is in the a-z range. The program does not recognize any space, symbols or any kind of punctuation marks. Any time the user enters any of this character the program is going to repeatedly ask for the...

  • Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the user to enter a string which is subsequently displayed in uppercase. It is...

    Your assignment is to write an assembly language program which read a string and print it in uppercase. This program asks the user to enter a string which is subsequently displayed in uppercase. It is important to first ensure that string to be converted is in the a-z range. The program does not recognize any space, symbols or any kind of punctuation marks. Any time the user enters any of this character the program is going to repeatedly ask for...

  • Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the...

    Python program. Character-Analysis Program Problem Statement: Design a program - IN PYTHON - that asks the user to enter a string. The string will then be displayed back to the user. This is followed by determining the number of alphabetic characters, numeric characters, lower_case letters, upper_case letters, whitespace characters, and then displaying them. The user should be given additional chances to enter additional strings, and each time a string is entered, the above process is to be performed. The inputting...

  • Using the Arduino IDE, write a program for an Arduino board that will perform the following three...

    Using the Arduino IDE, write a program for an Arduino board that will perform the following three tasks: 1. Input: Prompt the user to enter a character string. Read the character string from your computer through the Arduino's serial interface. 2. Processing: Convert lowercase characters to uppercase and uppercase characters to lowercase, and 3. Output: Return the processed string through the serial output and display it on your computer screen. Example: If the input character string is, “Here I am”,...

  • in Python: •Flip case: Write a program to do the following: •Accept the input of a...

    in Python: •Flip case: Write a program to do the following: •Accept the input of a sentence from the user that contains lowercase, uppercase, and special characters. •Make a new sentence in which the lowercase characters are changed to uppercase and the uppercase are changed to lower case.   All other characters will retain their original value. Print the original sentence and the new sentence.

  • Take the following C++ code and add to it the following: Write a program that reads...

    Take the following C++ code and add to it the following: Write a program that reads a string and outputs the number of times each lowercase vowel appears in it. Your program must contain a function with one of its parameters as a char variable, and if the character is a vowel, it increments that vowel's count. #include<iostream> #include<string> using namespace std; int countVowel(char, char); int main(void) { string str1; int countA = 0; int countE = 0; int countI...

  • Write a program that inputs a string from the user representing a password, and checks its...

    Write a program that inputs a string from the user representing a password, and checks its validity. A valid password must contain: -At least 1 lowercase letter (between 'a' and 'z') and 1 uppercase letter (between 'A' and 'Z'). -At least 1 digit (between '0' and '9' and not between 0 and 9). At least 1 special character (hint: use an else to count all the characters that are not letters or digits). -A minimum length 6 characters. -No spaces...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT