0% found this document useful (0 votes)
39 views9 pages

Shoeb - CLP - 03

The document contains details of a student named Md Shoeb Sikder Pappu enrolled in the Artificial Intelligence Lab course with course code CSE-404 at the Department of Computer Science and Engineering at Green University of Bangladesh for the spring semester of 2022. It lists the student's name and ID and includes examples of Python code solutions to common AI problems submitted by the student for the course.

Uploaded by

Shoeb
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)
39 views9 pages

Shoeb - CLP - 03

The document contains details of a student named Md Shoeb Sikder Pappu enrolled in the Artificial Intelligence Lab course with course code CSE-404 at the Department of Computer Science and Engineering at Green University of Bangladesh for the spring semester of 2022. It lists the student's name and ID and includes examples of Python code solutions to common AI problems submitted by the student for the course.

Uploaded by

Shoeb
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/ 9

Green University of Bangladesh

Department of Computer Science and Engineering (CSE)


Faculty of Sciences and Engineering

Semester: (Spring, Year: 2022), B.Sc. in CSE (Day)

CLP-3

Course Title:Artificial Intelligence Lab

Course Code: CSE-404

Student Details

Name ID

Md Shoeb Sikder Pappu 193002041


Print First 10 natural numbers using while loop

Ans:

username = input("Enter username:")


Shoeb = 1
while(Shoeb<=10):
print(Shoeb)
Shoeb += 1
else:
print("Done")

Output:
Display Fibonacci series up to 10 terms

Ans:

a=int(input("Enter the terms"))


f=0
s=1
if a<=0:
print("The series is",f)
else:
print(f,s,end=" ")
for x in range(2,a):
next=f+s
print(next,end=" ")
f=s
s=next

Output:
Calculate the cube of all numbers from 1 to a given
Number

Ans:

N = int(input("Enter value of N: "))


cube = 0
for i in range(1, N+1):
cube += (i*i*i)

print("Sum of cubes = ", cube)

Output:
Write a program to print the following patterns

Ans:

r = int(input("Enter the number of rows: "))


for i in range(0, r):
for j in range(0, i + 1):
print("*", end=' ')
print(" ")
for i in range(r , 0, -1):
for j in range(0, i - 1):
print("*", end=' ')
print(" ")

Output:
Ans:

num = int(input("Enter the number: "))


for i in range(0, 5):
for j in range(0, i + 1):
char = chr(num)
print(f"{char} ", end="")
num = num + 1
print("\r")

Output:
Python program to interchange first and last elements in
a list

Ans:

a=[]
n= int(input("Enter the number of elements in list:"))
for x in range(0,n):
element=int(input("Enter element" + str(x+1) + ":"))
a.append(element)
temp=a[0]
a[0]=a[n-1]
a[n-1]=temp
print("interchange first and last elements:")
print(a)

Output:
Python program to find second largest number in a
list
Ans:

import array
arr = []
n = int(input("enter size of array : "))
for x in range(n):
x=int(input("enter Number : "))
arr.append(x)
sorted_array = sorted(array.array('i', arr))
for i in range(len(arr)-1, 0, -1):
if sorted_array[i]!=sorted_array[i-1]:
print(f"second largest Number is {sorted_array[i-1]}")
break

Output:
Python program to print all prime numbers in a range
Ans:
First = int(input("Enter First Number: "))
Secound = int(input("Enter Secound Number: "))

for num in range(First, Secound + 1):


if num > 1:
for i in range(2, (num//2)+1):
if (num % i) == 0:
break
else:
print("Prime number ", num)

Output:

You might also like