0% found this document useful (0 votes)
60 views11 pages

Celsius to Fahrenheit Conversion

The document outlines a series of experiments conducted using Python 3.5, covering various programming concepts such as data types, arithmetic operations, string manipulation, date formatting, list operations, tuples, dictionaries, finding the largest number, temperature conversion, and pattern printing. Each experiment includes an aim, source code, input and output examples, and conclusions summarizing what was learned. The experiments are part of a curriculum at the Department of Computer Science and Information Technology, Rabindranath Tagore University Bhopal.
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)
60 views11 pages

Celsius to Fahrenheit Conversion

The document outlines a series of experiments conducted using Python 3.5, covering various programming concepts such as data types, arithmetic operations, string manipulation, date formatting, list operations, tuples, dictionaries, finding the largest number, temperature conversion, and pattern printing. Each experiment includes an aim, source code, input and output examples, and conclusions summarizing what was learned. The experiments are part of a curriculum at the Department of Computer Science and Information Technology, Rabindranath Tagore University Bhopal.
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

EXPERIMENT NO - 1

AIM:

Write a program to demonstrate different number data types in Python.

Apparatus Required:

PYTHON 3.5

SOURCECODE:
a=5
print(a, "is of type", type(a))
a = 2.0
print(a, "is of type", type(a))
a = 1+2j
print(a, "is complex number?", isinstance(1+2j,complex))
INPUT AND OUTPUT:
5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is complex number? True
5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is complex number? True

CONCLUSIONS:

Different number data types has been studied.

Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 1
EXPERIMENT NO - 2
AIM:

Write a program to perform different Arithmetic Operations on numbers in Python.

Apparatus Required:

PYTHON 3.5

SOURCECODE:
x = 15
y=4

Output: x + y
= 19 print('x + y
=',x+y)

Output: x - y
= 11 print('x - y
=',x-y)

Output: x * y
= 60 print('x * y
=',x*y)

Output: x / y =
3.75 print('x / y
=',x/y)

Output: x ** y =
print('x ** y =',x**y)

INPUT AND OUTPUT:

x + y = 19
x - y = 11
x * y = 60
x / y = 3.75
x // y = 3
x ** y = 50625
CONCLUSIONS:

Different arithmetic operations on numbers in python have been studied.

Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 2
EXPERIMENT NO -3

AIM:

Write a program to create, concatenate and print a string and accessing sub string from a
given string.

Apparatus Required:

PYTHON 3.5

SOURCECODE:
all of the following are equivalent
my_string = 'Hello' print(my_string)
my_string = "Hello"
print(my_string)
my_string = '''Hello'''
print(my_string)
triple quotes string can extend multiple lines my_string
= """Hello, welcome to
the world of Python"""
print(my_string)
c=" mlritm"
print(my_string+c)
substring function

print(my_string[5:11])

INPUT AND OUTPUT:

Hello
Hello
Hello
Hello, welcome to
the world of Python
Hello, welcome to
the world of Python mlritm
, welc

CONCLUSION :

A string and accessing sub- string fron a given string has been studied.
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 3
EXPERIMENT NO -4
AIM:

Write a python script to print the current date in the following format “Sun May 29

[Link] IST 2017”.

Apparatus Required:

PYTHON 3.5

SOURCECODE:

from datetime import date

today =[Link]()

# dd/mm/YY
d1 =[Link]("%d/%m/%Y")
print("d1 =", d1)

Textual month, day and year


d2 =[Link]("%B %d,
%Y") print("d2 =", d2)

mm/dd/y
d3 =[Link]("%m/%d/%y")
print("d3 =", d3)

Month abbreviation, day and


year d4 =[Link]("%b-%d-
%Y") print("d4 =", d3)

INPUT AND OUTPUT:


d1 = 25/12/2018
d2 = December 25, 2018
d3 = 12/25/18
d4 = 12/25/18
CONCLUSION:
A python script to print the current date in the given format has been studied.

Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 4
EXPERIMENT NO -5

AIM:

Write a program to create, append, and remove lists in python.

Apparatus Required:

PYTHON 3.5
SOURCECODE:
my_list = ['p','r','o','b','l','e','m']
my_list.remove('p')

Output: ['r', 'o', 'b', 'l', 'e',


'm'] print(my_list)

Output: 'o'
print(my_list.pop(1))

Output: ['r', 'b', 'l', 'e',


'm'] print(my_list)

Output: 'm'
print(my_list.pop())

Output: ['r', 'b',


'l', 'e']
print(my_list)

my_list.clear()

Output: []
print(my_list)

INPUT AND OUTPUT:

my_list=['p','r','o','b','l','e','m']
>>>my_list[2:3]=[]
>>>my_list
['p','r','b','l','e','m']
>>>my_list[2:5]=[]
>>>my_list
['p','r','m']
CONCLUSION :
A program has been studied to create , append and remove lists in python .

Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 5
EXPERIMENT NO -6

AIM:

Write a program to demonstrate working with tuples in python.

Apparatus Required:

PYTHON 3.5

SOURCECODE:

empty tuple
Output: ()
my_tuple =
()
print(my_t
uple)

tuple having integers


Output: (1, 2, 3)
my_tuple = (1,
2, 3)
print(my_tuple)

tuple with mixed datatypes


Output: (1, "Hello",
3.4) my_tuple = (1,
"Hello", 3.4)
print(my_tuple)

nested tuple
Output: ("mouse", [8, 4, 6], (1, 2,
3)) my_tuple = ("mouse", [8, 4, 6],
(1, 2, 3)) print(my_tuple)

tuple can be created without parentheses


also called tuple packing
Output: 3, 4.6, "dog"

my_tuple = 3, 4.6, "dog"


print(my_tuple)

tuple unpacking is also possible


Output:

Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 6
3
4.6
dog
a, b, c = my_tuple
print(a)
print(b)
print(c)

INPUT AND OUTPUT

()
(1, 2, 3)
(1, 'Hello', 3.4)
('mouse', [8, 4, 6], (1, 2, 3))
(3, 4.6, 'dog')
3
4.6
dog

CONCLUSION :

Working with tuples has been studied in python .

Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 7
EXPERIMENT NO -7

AIM:

Write a program to demonstrate working with dictionaries in python.

Apparatus Required:

PYTHON 3.5

SOURCECODE:
my_dict = {'name':'Jack', 'age': 26}
Output: Jack
print(my_dict['na
me'])
Output: 26
print(my_dict.get('age'))
Trying to access keys which doesn't exist throws error
my_dict.get('address')
my_dict['address']

INPUT AND OUTPUT:

Jack
26

CONCLUSION :
Working with dictionaries has been studied in python.

Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 8
EXPERIMENT NO -8
AIM:

Write a python program to find largest of three numbers.

Apparatus Required:

PYTHON 3.5

SOURCECODE:

Python program to find the largest number among the three input numbers

change the values of num1, num2 and num3


for a different result
num1 = 10
num2 = 14
num3 = 12
uncomment following lines to take three numbers from
user #num1 = float(input("Enter first number: "))
#num2 = float(input("Enter second number: "))
#num3 = float(input("Enter third number: "))
if (num1 >= num2) and (num1 >= num3):
largest = num1
elif (num2 >= num1) and (num2 >= num3):
largest = num2
else:
largest = num3

print("The largest number between",num1,",",num2,"and",num3,"is",largest)


INPUT AND OUTPUT:

The largest number between 10, 14 and 12 is 14.0

CONCLUSION :

A prgram in which largest of three number has been studied in python .

Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 9
EXPERIMENT NO -9

AIM:

Write a Python program to convert temperatures to and from Celsius,


Fahrenheit. [ Formula : c/5 = f-32/9 ]

Apparatus Required:

PYTHON 3.5

SOURCECODE:
Python Program to convert temperature in celsius to fahrenheit

change this value for a different result


celsius = 37.5

calculate fahrenheit
fahrenheit = (celsius * 1.8)
+ 32
print('%0.1f degree Celsius is equal to %0.1f degree Fahrenheit' %(celsius,fahrenheit))

INPUT ANDOUTPUT:

37.5 degree Celsius is equal to 99.5 degree Fahrenheit

CONCLUSION :
Conversion of temperature has been studied .

Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 10
EXPERIMENT NO -10

AIM:

Write a Python program to construct the following pattern, using a nested for loop

*
**
***
****
*****
****
***
**
*
Apparatus Required:

PYTHON 3.5

SOURCECODE:
n=5;
for i in range(n):
for j in range(i):
print ('* ', end="")
print('')
for i in range(n,0,-
1):
for j in range(i):
print('* ', end="")
print('')

INPUT ANDOUTPUT:
*
**
***
****
*****
****
***
**
*

CONCLUSION :
A program has been studied to construct the pattern , using a nested loop in python .
Department Of Computer Science and Information Technology, Rabindranath Tagore University Bhopal Page 11

Common questions

Powered by AI

Python's 'strftime' method allows for various date formats: using '%d/%m/%Y' results in '25/12/2018', '%B %d, %Y' provides 'December 25, 2018', '%m/%d/%y' results in '12/25/18', and '%b-%d-%Y' also produces '12/25/18' . These formats vary from numeric day/month/year to full-month-name and abbreviation styles, offering flexibility depending on the desired depiction of the date.

In Python, arithmetic operations with integers return integer results when possible, such as integer division returning the floor of the division ('x // y'). Operations with floats yield float results regardless of whether the division is exact or not: 'x / y' where 'x = 15, y = 4' results in '3.75', showcasing preservation of decimal precision . Float operations offer more precise control of mathematical outcomes compared to integer-only operations.

The technique involves conditional statements verifying each pair of the three numbers to identify the largest. The code uses 'if', 'elif', and 'else' blocks to compare numbers: starting with 'num1 >= num2' and 'num1 >= num3', then moving to 'num2' comparisons if the first condition fails . This method efficiently determines the largest by ensuring every number is compared, guaranteeing a solution irrespective of input order.

Temperature conversion in Python uses the formula 'fahrenheit = (celsius * 1.8) + 32'. By substituting the Celsius value into this equation, Python computes the Fahrenheit equivalent accurately, as seen with 'celsius = 37.5' resulting in '99.5' Fahrenheit . This direct formula application ensures straightforward implementation and reliable conversion outcomes.

In Python, dictionary values are accessed using keys, as in 'my_dict['name']' returning 'Jack' or 'my_dict.get('age')' returning '26' . Using 'get()' prevents errors when accessing keys that might not exist, returning 'None' instead. Direct access via 'my_dict['address']' raises a KeyError if the key is absent, highlighting the need for error handling or pre-validation when unsure of a key's presence.

Nested loops iterate through multiple levels, each corresponding to a layer of the pattern. For example, a loop through 'n = 5' rows with an inner loop iterating 'i' times prints a triangle of '*', then reverses to reduce '*' count in subsequent rows . This dual-loop setup enables complex pattern creation and control over multi-dimensional structures, demonstrating structured problem-solving via iterative execution.

Tuple packing allows multiple values to be assigned to a single tuple variable without parentheses, as in 'my_tuple = 3, 4.6, "dog"' . Tuple unpacking retrieves these values into individual variables such as 'a, b, c = my_tuple', resulting in 'a = 3', 'b = 4.6', and 'c = "dog"'. This facilitates simultaneous assignment and ease of access to components, demonstrating compactness and readability in code structure.

Python lists are mutable sequences that can have their size modified; elements can be added, removed, or changed. Appending elements increases the list size, while removing elements either by value (e.g., 'my_list.remove('p')') or index (e.g., 'my_list.pop()') decreases it . Lists maintain order and allow direct element access and modification, making them versatile for dynamic data collection.

Python supports various number data types including integers, floating-point numbers, and complex numbers. When a variable is assigned a value, Python automatically sets its type accordingly, as demonstrated by the expression 'a = 5' resulting in 'int', 'a = 2.0' resulting in 'float', and 'a = 1+2j' being identified as a complex number . This automatic type assignment allows developers to seamlessly switch between different numeric types without needing explicit type declarations.

Python strings can be defined using single, double, or triple quotes, enabling creation of single or multi-line strings . Concatenation uses the '+' operator, e.g., 'my_string + "c"', to join strings. Substring extraction employs slicing, such as 'my_string[5:11]', selecting specific sections of the string. These operations provide flexibility in handling textual data, allowing developers to manipulate and format strings as needed.

You might also like