GOA COLLEGE OF ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING
SUBJECT: Fundamentals of Computing Using Python
FACULTY: Prof. AMIT P. PATIL
CLASS: FE Comp (Sem-II)
PLATFORM: Spyder
YEAR: 2026
PYTHON ASSIGNMENT 01
Pattern 1: Inverted triangle of stars
n = int(input("Enter rows: "))
for i in range(n):
for j in range(i):
print(' ', end='')
for k in range(2*(n-i)-1):
print('*', end='')
print()
Output:
Pattern 2: Diamond of stars
n = int(input("Enter the no of rows of upper side of diamond: "))
for i in range(1, n+1):
for j in range(0, n-i):
print(end=' ')
for k in range(1, 2*i):
print('*', end='')
print()
for i in range(n-1, 0, -1):
for j in range(0, n-i):
print(end=' ')
for k in range(1, 2*i):
print('*', end='')
print()
Output:
Pattern 3: Rectangle border of stars
r = int(input("Enter the no of rows: "))
c = int(input("Enter the no of columns: "))
for i in range(0, r):
for j in range(0, c):
if(i==0 or i==(r-1) or j==0 or j==(c-1)):
print('*', end='')
else:
print(' ', end='')
print()
Output:
Pattern 4: Number pyramid
n = int(input("Enter the no of rows: "))
for i in range(1, n+1):
for j in range(0, n-i):
print(' ', end='')
for k in range(i, 2*i):
print(k, end='')
for k in range(2*i-2, i-1, -1):
print(k, end='')
print()
Output:
Q2) Predict the o/p of followings:
I. for i in range(7,-2,-9):
for j in range(i):
print(j)
II. x=19 print(x>>3)
III. print(27*2//3**3%4)
IV. x=20 and y=21 Print(x^y)
V. when x=33 print(~x)
# a)
for i in range(7, -2, -9):
for j in range(i):
print(j)
# b)
x = 19
print('x>>3 is: ', x>>3)
# c)
print('Answer is: ', 27*2//3**3%4)
# d)
x = 20
y = 21
print('x^y is: ', x^y)
# e)
x = 33
print('~x is ', ~x)
Output:
Q3) Write a python program to create a map with the following elements.
{11: 'margao', 20: 'vasco', 15: 'ponda', 70: 'panjim'}
Perform the following operations:
a) Print all the keys
b) Print all the values
c) Update value of key 20 to 'mapusa'
d) Delete key 15 and display all elements again.
x = {11:'margao', 20:'vasco', 15:'ponda', 70:'panjim'}
print([Link]())
print([Link]())
x[20] = 'mapusa'
del x[15]
print(x)
Output:
Q4) Write python program to find first 10 prime numbers
for num in range(2, 30):
count = 0
for i in range(1, num+1):
if num % i == 0:
count += 1
if count == 2:
print(num, end=' ')
Output:
Q5) Write python program to print sin series (given angle in deg)
import math
x = float(input("Enter angle in degrees: "))
n = int(input("Enter number of terms: "))
# convert degree to radians
x = x * [Link] / 180
sum = 0
sign = 1
for i in range(1, 2*n, 2):
sum += sign * (x**i) / [Link](i)
sign *= -1
print("sin(x) =", sum)
Output:
Q6) Write python program to find GCD of 2 numbers
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
gcd = 1
for i in range(1, min(a, b) + 1):
if a % i == 0 and b % i == 0:
gcd = i
print("GCD =", gcd)
Output:
Q7) Write python program to find exponential series
import math
x = float(input("Enter value of x: "))
n = int(input("Enter number of terms: "))
sum = 1
for i in range(1, n):
sum += (x**i) / [Link](i)
print("e^x =", sum)
Output:
Q8) Explain command line arguments in python with relevant code
Command line arguments are inputs given to a Python program through the terminal/command
prompt at the time of execution. In Python, they are handled using the [Link] list from the sys
module.
[Link][0] -> program name
[Link][1], [Link][2] -> arguments given by user
All arguments are stored as strings, so we convert them when needed.
import sys
[Link] = ['[Link]', '5', '10']
print([Link])
if len([Link]) < 3:
print("Please provide 2 numbers")
else:
a = int([Link][1])
b = int([Link][2])
print("Sum =", a + b)
Output: