[go: up one dir, main page]

0% found this document useful (0 votes)
71 views3 pages

Test 1 - Jupyter Notebook

This document contains 10 code snippets that demonstrate various Python programming concepts like string manipulation, data types, conditional statements, loops, functions, etc. Each code snippet accepts user input, performs some operation, and prints the output. The snippets include programs to reverse a name, calculate value of n+nn+nnn, check if a value is in a list, calculate sum between 15-20, print a pattern, find factorial of a number, convert tuple to string, and print first letter name pattern.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views3 pages

Test 1 - Jupyter Notebook

This document contains 10 code snippets that demonstrate various Python programming concepts like string manipulation, data types, conditional statements, loops, functions, etc. Each code snippet accepts user input, performs some operation, and prints the output. The snippets include programs to reverse a name, calculate value of n+nn+nnn, check if a value is in a list, calculate sum between 15-20, print a pattern, find factorial of a number, convert tuple to string, and print first letter name pattern.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

3/2/22, 1:17 PM test 1 - Jupyter Notebook

In [3]:

#1. Write a Python program which accepts the user's first and
# last name and print them in reverse order with a space between them.
a=input("input your first name: ")
b=input("input your last name: ")
print(b[::-1],"",a[::-1])

input your first name: vladmir

input your last name: putin

nitup rimdalv

In [2]:

#2. Write a Python program that accepts an integer (n) and


# computes the value of n+nn+nnn.
a = int(input("Input an integer : "))
n1 = int( "%s" % a )
n2 = int( "%s%s" % (a,a) )
n3 = int( "%s%s%s" % (a,a,a) )
print (n1+n2+n3)

Input an integer : 3

369

In [1]:

#3. Write a Python program to check whether a specified value is


# contained in a group of values.
A = int(input('Enter a value'))
B = input('Enter a number to check if its in the value of numbers')
C= 0
search = B.split()
for i in range(0,len(search)):
if A == int(search[i]):
C = 1
break;

if C == 1:
print('True')
else:
print('False')

Enter a value5

Enter a number to check if its in the value of numbers4

False

In [8]:

#5. Write a Python program to solve (x + y) * (x + y).


x=int(input("enter first value: "))
y=int(input("enter second value: "))
print((x+y)*(x+y))

enter first value: 5

enter second value: 2

49

localhost:8888/notebooks/test 1.ipynb 1/3


3/2/22, 1:17 PM test 1 - Jupyter Notebook

In [15]:

#6. Python program to generate a logic to get a below mentioned


# pattern.
for row in range(1,6):
for col in range(row):
print(row,end=' ')
print()

2 2

3 3 3

4 4 4 4

5 5 5 5 5

In [17]:

#4. Write a Python program to sum of two given integers. However,


# if the sum is between 15 to 20 it will return 20
n1=int(input('Enter number first : '))
n2=int(input('Enter number second : '))
s=n1+n2
if s>14 or s<21:
print('your sum is 20')
else:
print('invalid')

Enter number first : 7

Enter number second : 8

your sum is 20

In [21]:

#10. Program to find factorial of a user defined number.


num=int(input("enter a number: "))
factorial=1
if num < 0:
print("Sorry, factorial does not exist for negative numbers")
elif num == 0:
print("The factorial of 0 is 1")
else:
for i in range(1,num + 1):
factorial*=i
print("The factorial of",num,"is",factorial)

enter a number: 5

The factorial of 5 is 120

In [25]:

#8. Write a python program to convert tuple to a string.


a=(1,2,3,4,5)
b=str(a)
print(type(b))

<class 'str'>

localhost:8888/notebooks/test 1.ipynb 2/3


3/2/22, 1:17 PM test 1 - Jupyter Notebook

In [35]:

Input In [35]

elif (row==0 or row==2) or (col==0 or col==3):

SyntaxError: invalid syntax

In [38]:

#9. Program to print first letter of your name using characters pattern.
for row in range(5):

for col in range(4):

if (row==0 and col==3) or (row==2 and col==3):

print('',end=' ')

elif (row==0 or row==2) or (col==0 or col==3):

print('#',end=' ')

else:

print(' ',end=' ')


print()

# # #

# #

# # #

# #

# #

In [*]:

l=input('enter the list: ').split(',')


v=[]
for i in l:
print(l[2])
l.pop(2)
print(l)

In [ ]:

localhost:8888/notebooks/test 1.ipynb 3/3

You might also like