0% found this document useful (0 votes)
14 views

PROGRAM1

Python program

Uploaded by

drewgaming713
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

PROGRAM1

Python program

Uploaded by

drewgaming713
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAM :

##Circulate the values of


n variables
n = int(input("Enter
number of values : "))
list1 = []
for val in range(0,n,1):
ele = int(input("Enter
integer : "))
list1.append(ele)
print("Circulating the
elements of list ", list1)
for val in range(0,n,1):
ele = list1.pop(0)
list1.append(ele)
print(list1
Program 1 (a) Python program to swap two variables
x=5
y = 10
# To take inputs from the user
#x = input('Enter value of x: ')
#y = input('Enter value of y: ')
# create a temporary variable and swap the values
temp = x
x=y
y = temp
print('The value of x after swapping: {}'.format(x))
print('The value of y after swapping: {}'.format(y))
Output
The value of x after swapping: 10
The value of y after swapping: 5
Without Using Temporary Variable
x=5
y = 10
x, y = y, x
print("x =", x)
print("y =", y)

swapping two variable using arithmetic operators


s = 22
t = 55

s=s+t
t=s-t
s=s-t
print("The value of s after using Addition and
Subtraction operator is:", s)
print("The value of t after using Addition and
Subtraction operator is:", t)
PROGRAM :1 (b)
Circulate the values of n variables

n = int(input("Enter number of values : "))


list1 = []
for val in range(0,n,1):
ele = int(input("Enter integer : "))
list1.append(ele)
print("Circulating the elements of list ", list1)
for val in range(0,n,1):
ele = list1.pop(0)
list1.append(ele)
print(list1)
Output:

OUTPUT :
Enter number of values :
4
Enter integer : 10
Enter integer : 53
Enter integer : 57
Enter integer : 18
Circulating the elements
of list [10, 53, 57, 18]
[53, 57, 18, 10]
[57, 18, 10, 53]
[18, 10, 53, 57]
[10, 53, 57, 18]
OUTPUT :Enter number of values : 4
Enter integer : 10
Enter integer : 53
Enter integer : 57
Enter integer : 18
Circulating the elements of list [10, 53, 57, 18]
[53, 57, 18, 10]
[57, 18, 10, 53]
[18, 10, 53, 57]
[10, 53, 57, 18]

You might also like