Write an expression whose value is the character at index 3 of the str associated with s.

plz answer these short Qs in python language thanks

Q1- Write an expression whose value is the character at index 3 of the str associated with s.

Q2- Write an expression whose value is the str that consists of the third to last character of the str associated with s.

Q3- Assume that given, middle and family are three variables of type String that have been assigned values. Write an expression whose value is a String consisting of the first character of given followed by a period followed by the first character of middle followed by a period followed by the first character of family followed by a period: in other words, the initials of the name. So if the values of these three variables were "John" "Fitzgerald" "Kennedy", then the expression's value would be "J.F.K.".

Q4- Write an expression whose value is the str that consists of the first four characters of the str associated with s.

Answer

Question 1:

Python program :

#asking user string
s=input("Enter string : ")
#print character at index 3
print("character at index 3 : ",s[3])

=====================

Output :

main.py 1 #asking user string 2 s=input(Enter string :) 3 #print character at index 3 4 print(character at index 3 : ,s[3

*********************************************

Question 2:

Python program :

#asking user string
s=input("Enter string : ")
#print str that consists of the third to
#last character of the str
print(s[3:len(s)])

===================

Output :

main.py 1 #asking user string 2 s=input(Enter string : ) 3 #print str that consists of the third to #Last character of the

*********************************************

Question 3:

Python program :

#asking user value for given
given=input("Enter given : ")
#asking user value for middle
middle=input("Enter middle : ")
#asking user value for family
family =input("Enter family : ")
#print first character of each word
print(given[0]+"."+middle[0]+"."+family[0])

===================

Output :

main.py .. 1 #asking user value for given 2 given=input(Enter given : ) 3 #asking user value for middle 4 middle=input(Ent

*********************************************

Question 4:

Python program :

#asking user string
s=input("Enter string : ")
#print str that consists of the first
#four characters of the str
print(s[0:4])

===================

Output :

main.py 1 #asking user string 2 s=input(Enter string : ) 3 #print str that consists of the first 4 #four characters of the

*********************************************

Hottest videos

Leave a Reply

Your email address will not be published.

Related Posts