1.Write a program to take input from the user in following formats and also chec
ID: 3914957 • Letter: 1
Question
1.Write a program to take input from the user in following formats and also check their type by
using type function.
Formats: Integer, Float, String & Complex
2.Write a program for the following conditions:
- If a user enters a negative number it should break the loop
- If a user enters any positive value it will run the loop for infinite.
3.- Write a program to multiply the first 10 even integer number starting from 1 & store them in
result variable.
4.Write a program to concatenate the string of those characters which exist at the even
position in "innovationwithpython".
5.Write a function to return the list of those numbers in a range of 1 to 50 which is a multiple
of 2 and 6 both.
6.Write a function that takes three arguments which after concatenation should print
"innovationwithpython" . This is a void type function.
7.write a program to generate a dictionary that contains ( i , i * i ) such that is an integral
number between 1 and n (both included). and then the program should print the dictionary.
Suppose the following input is supplied to the program:
4
Then, the output should be:
{1: 1, 2: 4, 3: 9, 4: 16}
8.Write a program that read the sentence and gives the output as the length of each word in
a sentence in the form of a list.
9.Write a program which accepts a string from console and prints it in reverse order.
Explanation / Answer
1.
var1=int(input("enter integer"))
print (type(var1))
var2=float(input("enter float"))
print (type(var2))
var3=input("enter string")
print (type(var3))
Output:
enter integer345
<class 'int'>
enter float34
<class 'float'>
enter string23rwd
<class 'str'>
2.
num = 0
while(num>=0):
num = int(input("Enter a number: "))
Output:
Enter a number: 2
Enter a number: 0
Enter a number: -1
3.
num=2;
mult=1;
count=1;
result =[]
while(count<=10):
if(num%2==0):
mult=mult*num;
count=count+1;
result.append(mult)
num=num+1
print(result)
Output:
[2, 8, 48, 384, 3840, 46080, 645120, 10321920, 185794560, 3715891200]
4.
ss=""
string=input()
for i in string:
if(string.find(i)%2==0):
ss=ss+i
print(ss)
Output:
innovationwithpython
ivtiwitpt
5.
result =[]
for i in range(1, 50):
if(i%2==0 and i%6==0):
result.append(i)
print(result)
Output:
[6, 12, 18, 24, 30, 36, 42, 48]
6.
def concate(str1,str2,str3):
str4=str1+str2+str3
return str4
string1 = input("Enter first string to concatenate: ")
string2 = input("Enter second string to concatenate: ")
string3 = input("Enter third string to concatenate: ")
print(concate(string1,string2,string3))
Output:
Enter first string to concatenate: innovation
Enter second string to concatenate: with
Enter third string to concatenate: python
innovationwithpython
7.
result={}
n=int(input())
for i in range(1,n+1):
result[i]=i*i
print(result)
Output:
4
{1: 1, 2: 4, 3: 9, 4: 16}
8.
s=input()
print ([len(x) for x in s.split()])
Output:
this is an example program
[4, 2, 2, 7, 7]
9.
str1 =input()
str=""
for i in str1:
str = i + str
print(str)
Output:
this is the example
elpmaxe eht si siht
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.