UNIT 2
Python Variable, datatypes, Input and Output function and comments
AGENDA
.py is the file extension of python
1. OUTPUT FUNCTION
2. HOW TO USE VARIABLE
3. INPUT Function
4. COMMENT
//single comment
/*1. Airtime
2. Transfer
3. Balance
*/
single line
# a python program to display
multi line comment
"""
1. Airtime
2. Transfer
3. Balance
"""
print()
"""
# lab1
print("We are learning Artificial Intelligence using Python")
#lab2
print("You are welcome")age = 30course = "aritificial intelligence"
print(age)print(course)
#lab3
print("You are welcome")option = """
author: ajala
written date: 26-03-2023
topic: basis of python
"""
print(option)
#lab4a
print("You are welcome")
age = input("Enter your age")
course = input("Enter your course")
print(age)
print(course)
#lab4b
print("You are welcome")
print("Enter your age")
age = input()
print("Enter your course")
course = input()
print(age)
print(course)
print(username, "you are welcome")
Practice
# write a python program to ask the user for username#password and display the input to the user,# then display username, you are welcome ajala, you are welcome
"""
datatypes in python: int, float, str, bool,
#python program to calculate area of rectangle
#area = length x width
#lab5
print("You are welcome")
print("Enter your length")
length = float(input())
print("Enter your width")
width = float(input())
area = int(length) * int(width)
print(area)
List Data Structure
LIST: this is a collection which is ordered, allows changes and duplicates.it can store multiple items in a single variable.it is a built in datatype. it uses square brackets.
#empty list syntax
variableName = []
For example, declare and initialize an empty list variable called score
score = []
# to display index
variableName[indexValue]
"""
# python list to store and display some data
color = ["yellow", "black", "purple"]
cgpa = [3.2, 3.99, 4]
score = [1, 40, 39]
print(color)
print(cgpa)
print(score)
# python list to select a particular element
cgpa = [3.2, 3.99, 4]
print(cgpa[2])
"""
# python program to emulate ANN (Artificial Neural Network) using single input, single weight, single bias
inp = [3.2, 3.99, 4]
wgt = [-0.7, 2.4, 5.9]
b = 2
#formula of ANN calculation
#output = (sum(inputs*weights))+bias
out_data = (inp[0]*wgt[0] + inp[1]*wgt[1] + inp[2]*wgt[2]) + b
print(out_data)
Comments
Post a Comment