0% found this document useful (0 votes)
8 views22 pages

Navttcc Tasks

Navtc task problem for AI/ML course 2024

Uploaded by

zainali.x21
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)
8 views22 pages

Navttcc Tasks

Navtc task problem for AI/ML course 2024

Uploaded by

zainali.x21
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/ 22

TAS PROBLEM SOLUTION

K
3 # This
program adds
two numbers
num1 =
1.5
num2 =
6.3
# Add
two numbers
Sum =
num1 + num2
# Display
the sum
print('Th
e sum of {0} and
{1} is {2}'.format
(num1, num2,
sum) )
4 # Store input
numbers
num1 = input('
Enter first
number: )
num2 =
input('Enter
second number: )

# Add two
numbers
sum = float
(num1) + float
(num2)

# Display the
sum
print('The sum of
{0) and (1} is
{2}'.format
(num1,
num2, sum) )
5 # Python
Program to
calculate the
square root

# Note: change
this value for a
different result
num = 8

# To take the
input from the
user
#num =
float(input('Enter
a number:))

num_sqrt = num
** e.5
print('The square
root of %0.3f is
%0.3f %(num
„ num_sqrt) )
6 # Find square
root of real or
complex
numbers
# Importing the
complex math
module
import cmath

num = 1+2j

# To take input
from the user
#num =
eval(input ('
Enter a number:
'))

num_sqrt =
cmath. sqrt
(num)
print(' The
square root of {0}
is {1:0.3f}
+{2 :0.3f}j' .forma
t (num
, num_sqrt. real,
num_sqrt.
imag) )
7 # 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) )
8 # Python
Program to find
the area of
triangle

a=5
b= 6
C =7

# Uncomment
below to take
inputs from the
user
# a = float
(input(' Enter
first side: ))
# b = float
(input(' Enter
second side: '))
#c = float (input('
Enter third side:
'))

# calculate the
semi-perimeter
s = (a + b + c) / 2

# calculate the
area
area = (s* (s-a) *
(s-b) * (s-c)) **.5
print('The area of
the triangle is
%0.2f' %area)
9 # Solve the
quadratic
equation ax**2 +
bx + c = 0

# import complex
math module
import cmath

a=1
b= 5
C=6

# calculate the
discriminant
d = (b**2) -
(4*a*c)

# find two
solutions
soll = (-b-
cmath.sqrt
(d) ) /(2*a)
sol2 = (-
b+cmath.sqrt
(d) ) / (2*a)

print('The
solution are {0)
and
{1}'.format (sol1,
sol2) )
10 # Taking
kilometers input
from the user
kilometers =
float (input ("
Enter value in
kilometers: "))

# conversion
factor
conv_fac =
0.621371

# calculate miles

miles =
kilometers *
conv_fac

11 i = l0 1
if (i > 15) :
print ("10 is less
than l5")
print ("I am Not
in if")
12 i = 20;
if (i < 15) :
print ("i is
smaller than
15")
print ("i'm in if
Block")
else:
print ("i is
greater than
15")
print ("i'm in
else Block")
print ("i'm not in
if and not in else
Block")

13 i = 10 1
if (i = 10):
# First if
statement
if (i < 15) :
print ("i is
smaller than
15")
# Nested - if
statement
# Wil only be
executed if
statement
above
# it is true
if (i < 12):
print ("i is
smaller than 12
too")
else:
print ("i is
greater than
15")
14 i = 20

if (i == 10) :
print ("i is 10")
elif (i = 15) :
print ("i is 15")
elif (i == 20) :
print ("i is 20")
else:
print ("i is not
present")
15 # Python
program to
illustrate
# Iterating over
a list
l = ["geeks",
"for", "geeks"]

for i in l:
print(i)

# Iterating over
dictionary
print("Dictionary
Iteration")

d = dict()

d['xyz'] = 123
d['abc'] = 345
for i in d:
print("%
s % d" % (i, d[i])
# Iterating over
a String
print("String
Iteration")

s = "Geeks"
for i in s:
print(i)
for i in range(0, 10,
2):
print(i)
for i in range(1, 4):
for j in
range(1, 4):

print(i, j)

fruits = ["apple",
"banana", "cherry"]
colors = ["red",
"yellow", "green"]
for fruit, color in
zip(fruits, colors):
print(fruit,
"is", color)
t = ((1, 2), (3, 4), (5,
6))
for a, b in t:
print(a, b)

# Prints all letters


except 'e' and 's'

for letter in
'geeksforgeeks':

if letter ==
'e' or letter == 's':

continue

print('Current Letter
:', letter)
for letter in
'geeksforgeeks':

# break the
loop as soon it sees
'e'
# or 's'
if letter ==
'e' or letter == 's':

break

print('Current Letter
:', letter)

# An empty loop
for letter in
'geeksforgeeks':
pass
print('Last Letter :',
letter)
# Python Program
to
# show range()
basics

# printing a number
for i in range(10):
print(i,
end=" ")

# performing sum of
first 10 numbers
sum = 0
for i in range(1, 10):
sum = sum
+i
print("\nSum of first
10 numbers :", sum)

# Python program to
demonstrate
# for-else loop

for i in range(1, 4):


print(i)
else: # Executed because
no break in for
print("No Break\
n")
clothes = ["shirt", "sock",
"pants", "sock", "towel"]
paired_socks = []
for item in clothes:
if item == "sock":
continue
else:

print(f"Washing
{item}")
paired_socks.append("soc
ks")
print(f"Washing
{paired_socks}")

for day in range(1, 8):


distance = 3 +
(day - 1) * 0.5
print(f"Day {day}:
Run {distance:.1f} miles")
# Python program to
illustrate
# while loop
count = 0
while (count < 3):
count = count + 1
print("Hello
Geek")

age = 28

# the test condition is


always True
while age > 19:
print('Infinite
Loop')
# Prints all letters except
'e' and 's'
i=0
a = 'geeksforgeeks'

while i < len(a):


if a[i] == 'e' or a[i]
== 's':
i += 1
continue

print('Current
Letter :', a[i])
i += 1

# break the loop as soon


it sees 'e'
# or 's'
i=0
a = 'geeksforgeeks'

while i < len(a):


if a[i] == 'e' or a[i]
== 's':
i += 1
break

print('Current
Letter :', a[i])
i += 1
# An empty loop
a = 'geeksforgeeks'
i=0

while i < len(a):


i += 1
pass

print('Value of i :', i)

# Python program to
demonstrate
# while-else loop

i=0
while i < 4:
i += 1
print(i)
else: # Executed
because no break in
for
print("No
Break\n")

i=0
while i < 4:
i += 1
print(i)
break
else: # Not executed
as there is a break
print("No
Break")
a = int(input('Enter a
number (-1 to quit): '))

while a != -1:
a=
int(input('Enter a
number (-1 to quit): '))

# Initialize a counter
count = 0

# Loop infinitely
while True:
# Increment
the counter
count += 1
print(f"Count
is {count}")

# Check if the
counter has reached a
certain value
if count == 10:
# If so,
exit the loop
break

# This will be executed


after the loop exits
print("The loop has
ended.")
# checks if list still
# contains any
element
a = [1, 2, 3, 4]

while a:
print(a.pop())

# Python program to
illustrate
# Single statement
while block
count = 0
while (count < 5):
count += 1
print("Hello
Geek")
initial_height = 10
bounce_factor = 0.5
height = initial_height
while height > 0.1:
print("The ball
is at a height of",
height, "meters.")
height *=
bounce_factor
print("The ball has
stopped bouncing.")

countdown = 10
while countdown > 0:

print(countdown)
countdown -=
1
print("Blast off!")

You might also like