Python Output PDF
Python Output PDF
NO: 01
01. AREA AND PERIMETER OF A CIRCLE
DATE:
AIM
ALGORITHM
Step 2: the user to enter the radius of the circle and reads in the value as a string
using the input() function. The float() function is then used to convert the input
Step 3: calculates the area of the circle using the formula π*r^2. The value of π
is approximated to 3.142.
Step 4: calculates the perimeter of the circle using the formula 2*π*r.
Step 5: These lines print the area and perimeter of the circle using the print()
function. The values of a and p are inserted into the output strings using string
formatting
a=3.142*r*r
p=2*3.142*r
OUTPUT:
RESULT:
AIM:
ALGORITHM:
Step 2: The user to enter a value for n and reads it in as an integer using the
Step 3: Initializes the first two terms of the Fibonacci series, which are 0 and 1
Step 4: print the initial two terms of the series, which are 0 and 1
Step 5: The loop runs from the third term (i=2) up to the nth term (i=num1-1).
In each iteration of the loop, the current term (c) is calculated as the sum
The values of a and b are then updated to the previous two terms,
respectively. Finally, the current term is printed using the print() function
with end="" to prevent the cursor from moving to the next line.
num1=int(input("enter n value:"))
a=0
b=1
print("fibonacci series.....")
print("0 1",end="")
i=2
while(i<=num1-1):
c=a+b
a=b
b=c
print(c,end="")
i=i+1
OUTPUT:
RESULT
AIM
ALGORITHM
Step 2: Initialize the two numbers (num1 and num2) and the GCD (gcd) to 1
Step 3: loops through all possible factors of the smaller of the two numbers
(min(num1,num2)) and checks if they divide both num1 and num2 without a
remainder. If a factor is found, it is stored as the new value of gcd. The loop
Step 4: print() statement inside the loop is used to display the value of gcd
whenever a new factor is found that divides both num1 and num2.
num1=36
num2=60
gcd=1
gcd=i
print("GCD of ",num1,"and",num2,"is",gcd)
OUTPUT
RESULT
DATE:
N PRIME NUMBER
AIM
ALGORITHM
Step 2: This code takes an integer input from the user and generates a list of
Step 3: The program starts by printing a message indicating the range of prime
Step 4: It then uses a nested loop to check if each number in the range from 1 to
number and is printed out. The "else" clause in the inner loop is executed only if
for n in range(1,numr):
for i in range(2,n):
if(n%i==0):
break
else:
print(n,end=' ')
OUTPUT:
RESULT:
AIM
ALGORITHM
Step2: The user to input a positive integer n, and then asks the user to input n
natural numbers.
Step3: For each number entered, it squares it and adds the result to a running
sum sum. After each iteration, the program prints out the current value of the
sum.
Step4: One thing to note is that the input statement inside the for loop should
specify that the input should be a natural number, not a float, since the program
sum=0
for i in range(1,n+1):
sum=sum+(m*m)
RESULT:
AIM
ALGORITHM
Step2: Initializes a variable called "sum" with a value of 0. This variable will be
Step3: Starts a for loop that will iterate through each element in the array. The
loop variable "i" will take on the values 0, 1, 2, 3, and 4 (since the length of the
array is 5).
Step4: Adds the current element in the array (arr[i]) to the variable "sum".
Step5: After the loop has finished iterating through all the elements in the array,
# initialize array
arr=[1,2,3,4,5];
sum=0;
for i in range(0,len(arr)):
sum= sum+arr[i];
RESULT:
AIM
ALGORITHM
Step2:The function largest() takes two arguments: the array arr and its size n.
Step3: The max variable is initialized to the first element of the array arr[0], and
then the loop begins iterating through the array elements starting from the
second element.
Step4: If any element is found to be greater than the current maximum, then the
Step5: Finally, the function returns the maximum value. The Driver Code
initializes an array arr and its size n, calls the largest() function, and prints the
# in arr[] of size n
# in arr[] of size n
max = arr[0]
# current max
max = arr[i]
return max
# Driver Code
n = len(arr)
Ans = largest(arr, n)
RESULT
AIM:
ALGORITHM
Step2: The code works by using two pointers, one starting at the beginning of
the string (i=0) and the other starting at the end of the string (j=len(str)-1).
Step3: It then compares the characters at these two positions and moves the
pointers closer to each other until they meet in the middle of the string.
Step4: If any two characters don't match during the process, the string is not a
palindrome.
i=0
j=len(str)-1
isPalindrome=True
while i<=j:
if(str[i]!=str[j]):
isPalindrome=False
break
i+=1
j-=1
if isPalindrome:
print(f"{str} is Palindrome.")
else:
RESULT:
AIM:
ALGORITHM:
Step2: First, the program initializes a variable cont with the value 'Y'. This
variable will be used later to check if the user wants to continue adding strings
or not.
Step3: The program also initializes an empty list called mylist. This list will be
Step4:A while loop is used to repeatedly ask the user for input and store it in the
Step5:Inside the loop, the program prompts the user to enter a string using the
input() function and saves the user's input in a variable called myStr.
Step6:The program then adds myStr to the list mylist using the append()
function.The program then asks the user if they want to continue adding strings.
If the user enters 'Y' or 'y', the loop continues. Otherwise, the loop ends and the
Step7:Once the loop has ended, the program prints out all the elements in the
list using a for loop that iterates through each element in the list and prints it
out.
Step9:Overall, this program is a simple example of how to use Python lists and
control structures like while and for loops to process user input.
cont='Y'
mylist=[]
while cont.upper()=='Y':
mylist.append(myStr)
n=len(mylist)
for i in range(n):
print(mylist[i])
OUTPUT:
RESULT:
AIM:
ALGORITHM
Step2:Declare a string.
myList=[]
for i in range(n):
myList.append(myVal)
for i in range(n):
print(myList[i],end= "")
myList1=myList[::-1]
RESULT: