| Server IP : 172.64.80.1 / Your IP : 172.71.120.136 Web Server : Apache System : Linux mail.federalpolyede.edu.ng 5.10.0-32-amd64 #1 SMP Debian 5.10.223-1 (2024-08-10) x86_64 User : federalpolyede.edu.ng_idh35skikv ( 10000) PHP Version : 7.4.33 Disable Function : opcache_get_status MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/vhosts/federalpolyede.edu.ng/phd_code/pkg/ |
Upload File : |
# Question 1
print ("======= Output for Question One==============")
ex='Python is an interesting and useful language for numerical computing!'
a=len(ex)
# Question 1a
print(ex[slice(0,6)])
# Question 1b
print(ex[slice(a-1,a)])
# Question 1c
print(ex[slice(a-10,a-1)])
# Question 1d
print(ex[slice(a-4,a-2)])
# Question 1e
print(ex[slice(a,0,-1)]+ex[slice(0,1)])
# Question 1f
aspoa=ex[slice(a,0,-1)]+ex[slice(0,1)]
print(aspoa[slice(a-7,a)])
# Question 1g
print(ex[slice(0,a,2)])
# QUESTION 2
print ("======= Output for Question Two==============")
dic={"alpha":1.0,"beta":3.1415, "gamma":99}
# print(type(dic))
print('The Value of alpha is :',dic.get("alpha"))
#QUESTION 3
print ("======= Output for Question Three==============")
lis_original=[4,3.1415,1.0,2+4j,'Hello','World']
# print(type(lis))
# (Q3a) Delete 1.0 if you knew its position
q_3a1=[4,3.1415,1.0,2+4j,'Hello','World']
del q_3a1[2]
print(q_3a1)
# What if you didn’t know its position?
q_3a2=[4,3.1415,1.0,2+4j,'Hello','World']
q_3a2.remove(1.0)
print (q_3a2)
# Q3b
q_3b=[4,3.1415,1.0,2+4j,'Hello','World']
new_items=[1.0,2+4j,'Hello']
q_3b.extend(new_items)
print(q_3b)
# Q3c
q_3c=[4,3.1415,1.0,2+4j,'Hello','World']
q_3c.reverse()
print(q_3c)
# Q3d
print(q_3b.count('Hello'))
# Question 4
print ("======= Output for Question Four==============")
lis_matrix=[[1,5],[.5,1]]
print ("Value in (0,0) is ",lis_matrix[0][0])
print ("Value in (0,1) is ",lis_matrix[0][1])
print ("Value in (1,0) is ",lis_matrix[1][0])
print ("Value in (1,1) is ",lis_matrix[1][1])
# Question 5a
print ("======= Output for Question Five==============")
k=int(input("Enter a number: "))
# print(k**2)
print("The square of 5 is ", k**2)
# Question 5b
a=input("Enter weight in kilograms :")
k=int(a)
print ("The ",a,"in Kilogram is ",k*2.2)
# Question 6
print ("======= Output for Question Six==============")
a=input("Enter a string value")
result = ""
for letter in a:
result += letter * 2
print(result)
# Question 7
print ("======= Output for Question Seven==============")
value_in="Hello"
out=""
for char in value_in:
out += char * 2
print(out)
# Question 8
print ("======= Output for Question Eight==============")
import random
for i in range (1, 50):
print(random.randint(0,100))