Exp1
Exp1
Objective of Experiment: The aim of this experiment is to introduce and apply the fundamental concepts of
Python programming in the context of creative coding. This experiment will explore how core programming
constructs—such as variables, operators , control flow, loops, functions, and data structures—can be utilized to
create dynamic, expressive, and responsive digital art or generative designs.
Pre-Requisite:
Tools: Any IDLE, Juypter Notebook / google colab
Theory:
1.1. Introduction to Python 1.2. Basic Syntax and Variables 1. Integers (int)
● What is Python and where is ● Comments and ● Integers are whole
it used? indentation. numbers, positive or
negative, without
● Setting up Python on your ● Variables: declaring and
decimals.
system. assigning values. x = 10
o Install Python and y = -5
● Data types: int, float, str,
IDLE or use an print(x + y) # Output: 5
IDE (e.g., VSCode bool.
print(x * 3) # Output: 30
or PyCharm). ● Basic input/output:
o Brief on running
Python scripts and name = input("Enter your name: ")
using Python shell. print(f"Hello, {name}!")
Output: Grade B
Example 2: Iterating through a list Example 3: Looping through a Example 4: Nested for loop
string (Multiplication table)
fruits = ["apple", "banana", "cherry"]
for letter in "Python": for i in range(1, 4):
for fruit in fruits: print(letter) for j in range(1, 4):
print(fruit) print(f"{i} * {j} = {i * j}")
Output: P y t h o n
Output: apple,banana,cherry Output:
1*1=1
1*2=2
1*3=3
2*1=2
2*2=4
2*3=6
3*1=3
3*2=6
3*3=9
Output:Hello Alice!
Problem Description:
Area of Triangle -
Creating a program that reads 2 or 3 sides of a triangle and computes area of triangle. Area of the trinagle is
displayed to user
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
2. NA
Program: 1.
import math
def main():
print("Choose the method to calculate the area of the triangle:")
print("1. Using the lengths of all three sides")
print("2. Using the base and height")
if choice == '1':
try:
a = float(input("Enter the length of side a: "))
b = float(input("Enter the length of side b: "))
c = float(input("Enter the length of side c: "))
else:
print("Invalid choice. Please select either 1 or 2.")
if __name__ == "__main__":
main()
def main():
# Input from the user
try:
number = int(input("Enter the number for the multiplication
table: "))
limit = int(input("Enter the upper limit for the
multiplication: "))
if limit < 1:
print("Please enter a limit greater than 0.")
return
generate_multiplication_table(number, limit)
except ValueError:
print("Invalid input. Please enter valid integers.")
if __name__ == "__main__":
main()
Output: 1.
2.
Practice Programs:
1. Read 2 numbers from user and implement calculator with 4 basic operations
2. Read 2 strings and perform String concatenation.
3. Read radius of circle and print its area
4. Read temperature in Celsius and convert into Fahrenheit
5. Read principal amount, rate of interest and period and calculate simple interest
6. Read 2 numbers and swap their values.
7. Print sum of first N numbers.
8. Reverse a Given String using loop
9. Find Factorial of a Number
10. Find Sum of Digits in a Number
References:
Study Materials Online repositories:
1. Yashvant Kanetkar, “Let us Python: Python is 1. Python 3 Documentation: https://docs.python.org/3/
Future, Embrace it fast”, BPB Publications;1 3. "The Python Tutorial",
st edition (8 July 2019). http://docs.python.org/release/3.0.1/tutorial/
2. Dusty Phillips, “Python 3 object-oriented 4. http://spoken-tutorial.org
Programming”, Second Edition PACKT 5. Python 3 Tkinter library Documentation:
Publisher, August 2015. https://docs.python.org/3/library/tk.html
3. John Grayson, “Python and Tkinter 6. Numpy Documentation: https://numpy.org/doc/
Programming”, Manning Publications (1 March 7. Pandas Documentation: https://pandas.pydata.org/docs/
1999). 8. Matplotlib Documentation:
4. Core Python Programming, Dr. R. Nageswara https://matplotlib.org/3.2.1/contents.html
Rao, Dreamtech Press 9. Scipy Documentation :
5. Beginning Python: Using Python 2.6 and Python https://www.scipy.org/docs.html
3.1. James Payne, Wrox publication 10. Machine Learning Algorithm Documentation:
6. Introduction to computing and problem solving https://scikit-learn.org/stable/
using python, E Balagurusamy, 11. https://nptel.ac.in/courses/106/106/106106182/
McGrawHill Education 12. NPTEL course: “The Joy of Computing using Python”
Video Channels:
https://www.youtube.com/watch?v=t2_Q2BRzeEE&list=PLGjplNEQ1it8-0CmoljS5yeV-GlKSUEt0
https://www.youtube.com/watch?v=7wnove7K-ZQ&list=PLu0W_9lII9agwh1XjRt242xIpHhPT2llg
Data Visualization:
https://www.youtube.com/watch?v=_YWwU-gJI5U