0% found this document useful (0 votes)
13 views10 pages

Exp1

The document outlines an experiment for a Creative Coding in Python course at Fr. Conceicao Rodrigues College of Engineering, focusing on fundamental Python programming concepts. It includes objectives, prerequisites, theoretical background, and practical problem descriptions for calculating the area of a triangle and generating a multiplication table. Additionally, it provides references and resources for further learning in Python programming.

Uploaded by

lahaho6097
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)
13 views10 pages

Exp1

The document outlines an experiment for a Creative Coding in Python course at Fr. Conceicao Rodrigues College of Engineering, focusing on fundamental Python programming concepts. It includes objectives, prerequisites, theoretical background, and practical problem descriptions for calculating the area of a triangle and generating a multiplication table. Additionally, it provides references and resources for further learning in Python programming.

Uploaded by

lahaho6097
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/ 10

FR.

CONCEICAO RODRIGUES COLLEGE OF ENGINEERIG


Department of Mechanical Engineering

Academic Year 2024-2025 Estimated Experiment No. 1 – 02 Hours


Time
Course & Semester F.E. CE Subject Name Creative Coding in Python
Module No. 01 Chapter Title
Experiment Type Software Subject Code VSE11ME02
Performance

Name of Olin Xavier Lemos Roll No. 10303


Student

Date of 08/01/2025 Date of 08/01/2025


Performance.: Submission.
:
CO Mapping CO2: Demonstrate basic concepts of python programming.

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}!")

Common Operations: 2. Floating-point Numbers Common Operations:


(float)
● + (addition) ● Same as integers: +, -,
● Floats represent real *, /, etc., but results can
● - (subtraction)
numbers with a decimal have decimal points.
● * (multiplication) point.

● / (division, returns a float) a = 10.5


b = 3.2
● // (integer division, discards print(a + b) # Output: 13.7
the decimal part) print(a / b) # Output: 3.28125
● % (modulus, returns the
remainder)
● ** (exponentiation, e.g., x
** y means x to the power
of y)

3. Strings (str) Common Operations: word = "Python"


print(word[0]) # Output: P
● Strings are sequences of ● Concatenation (+):
(first character)
characters, enclosed in Combining strings. print(word[-1]) # Output: n
single or double quotes. (last character)
● Repetition (*): Repeating
print(word[1:4]) # Output: yth
greeting = "Hello" a string multiple times.
(slicing)
name = 'Alice' ● Indexing: Accessing print(word * 2) # Output:
message = greeting + ", " + PythonPython
individual characters
name + "!"
using an index (starting at
print(message) # Output:
0).
Hello, Alice!
● Slicing: Extracting
substrings using
[start:end].

String Methods: text = "Hello, World!" 4. Boolean (bool)


print(len(text)) # Output: 13
● len(): Returns the length of ● Booleans represent True
print(text.upper()) # Output:
a string. HELLO, WORLD! or False values. They are
print(text.replace("World", often used in conditional
● .upper(): Converts to
"Python")) # Output: Hello, statements.
uppercase. is_active = True
Python!
● .lower(): Converts to is_logged_in = False
print(is_active and is_logged_in)
lowercase.
# Output: False (both must be
● .replace(): Replaces a True)
substring. print(is_active or is_logged_in)
# Output: True (one must be True)

Logical Operations: x = 10 5. Type Checking and


y=5 Conversion
● and: Returns True if both
print(x > y) # Output: True
operands are true. ● type(): Used to check the
(comparison results in boolean)
print(x == y) # Output: False type of a variable.
● or: Returns True if at least
(equality check) ● int(), float(), str():
one operand is true.
print(not x > y) # Output: False
Convert between types.
● not: Inverts the boolean (inverted result)
value.

x = "123" user_input = input("Enter a


y = int(x) # Converts string to number: ")
integer converted_number =
z = float(x) # Converts string to float int(user_input) # Convert string
print(type(x)) # Output: <class 'str'> input to integer
print(type(y)) # Output: <class 'int'> print(converted_number * 2) #
print(type(z)) # Output: <class Perform operations on the
'float'> converted number
Control Flow

If-Else Statements Using elif 2. For Loops


If-else statements are used to make You can have multiple conditions For loops are used to iterate over
decisions based on conditions. using elif (else-if). sequences like lists, strings, or
ranges.
age = 18 marks = 75
Example 1: Looping over a
if age >= 18: if marks >= 90: range()
print("You are an adult.") print("Grade: A")
else: elif marks >= 75: # Print numbers from 0 to 4
print("You are a minor.") print("Grade: B") for i in range(5):
elif marks >= 60: print(i)
Output: print("Grade: C")
You are an adult. else: Output: 0 1 2 3 4
print("Grade: F")

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

3. While Loops Example 2: Using break in a Example 3: Using continue in a


While loops keep executing a block while loop loop
of code as long as a given condition break is used to exit the loop continue is used to skip the rest
is True. early. of the current iteration and
Example 1: Basic while loop count = 0 move to the next.
while count < 10: count = 0
count = 0 print(count) while count < 5:
while count < 5: if count == 5: count += 1
print(count) break # Exit loop when if count == 3:
count += 1 # increment count count reaches 5 continue # Skip the iteration
count += 1 # when count is 3
Output: 0 1 2 3 4 print(count)
Output: 0 1 2 3 4
Output: 1 2 4 5

4.Functions Functions can have default


Functions in Python are defined arguments, return values, and
using the def keyword. accept multiple parameters.

def greet(name): def add_numbers(a, b=5):


return f"Hello, {name}!" return a + b
message = greet("Alice") print(add_numbers(3)) # Output:
print(message) 8 (uses default value of b)

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

Multiplication Table Program-


Creating a Multiplication Table Program involves generating a table that displays the multiplication of
numbers in a structured format. The program can take number to be multiplies, an upper limit for the numbers
and produce a table showing each number multiplied by others up to that limit.
Input:1. 5 & 2 Output:1. The area of the Libraries:1. Math
triangle with base 5.0 and height
2. 5 & 5 2.0 is: 5.00 2. none

2.Multiplication Table for 5 up to


5:

5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25

Methods used in Libraries: math.sqrt(x)

2. NA

Program: 1.
import math

def area_with_sides(a, b, c):


# Using Heron's formula to calculate the area of a triangle given
its three sides
s = (a + b + c) / 2 # semi-perimeter
area = math.sqrt(s * (s - a) * (s - b) * (s - c))
return area

def area_with_base_height(base, height):


# Using the base and height to calculate the area of a triangle
return 0.5 * base * height

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")

choice = input("Enter your choice (1 or 2): ")

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: "))

# Check for the validity of the triangle


if a + b > c and a + c > b and b + c > a:
area = area_with_sides(a, b, c)
print(f"The area of the triangle with sides {a}, {b},
and {c} is: {area:.2f}")
else:
print("The lengths provided do not form a valid
triangle.")
except ValueError:
print("Invalid input. Please enter valid numbers.")

elif choice == '2':


try:
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))
area = area_with_base_height(base, height)
print(f"The area of the triangle with base {base} and
height {height} is: {area:.2f}")
except ValueError:
print("Invalid input. Please enter valid numbers.")

else:
print("Invalid choice. Please select either 1 or 2.")

if __name__ == "__main__":
main()

2. def generate_multiplication_table(number, limit):


# Print the header
print(f"Multiplication Table for {number} up to {limit}:")
print("-" * 30)

# Generate the multiplication table


for i in range(1, limit + 1):
result = number * i
print(f"{number} x {i} = {result}")

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

Programs and Outputs


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


6. Read the numbers and swap their values
Correctness & Logic & Problem Use of Python Timeline Total
Functionality Solving Approach Features (1 Marks) (10)
(3 Marks) with creativity (3 Marks)
(3 Marks)

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

You might also like