Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,157,936 members, 7,835,120 topics. Date: Tuesday, 21 May 2024 at 05:04 AM

Python 3: Exercises And Solutions. - Programming (4) - Nairaland

Nairaland Forum / Science/Technology / Programming / Python 3: Exercises And Solutions. (8997 Views)

Salesforce Rest API Example Using Python 3 / Consume Kibana Rest API Using Python 3 / How To Write A Guessing Game Program In Python 3 (2) (3) (4)

(1) (2) (3) (4) (5) (6) (Reply) (Go Down)

Re: Python 3: Exercises And Solutions. by Daddyshome: 8:49am On May 01, 2020
Collinsanele:


Nice but if there's no unique item, then, you would have an index error.
OK, then I'll put an if statement.
def unique_num(lis):
unique = [x for x in lis if lis.count(x) == 1]
if len(unique) > 0:
return unique[0]

1 Like

Re: Python 3: Exercises And Solutions. by Daddyshome: 8:54am On May 01, 2020
gbolly1151:

Check your code bro,it doesn't seem right
It's the indentation.
Re: Python 3: Exercises And Solutions. by Brukx(m): 11:32am On May 01, 2020
jayphe:

Collinsanele, Taofeekdboy, kensmoney another one is here!

Exercise 3

Write a Python program that accepts day, month and year from the user and prints the result in this form:

Today is 23/04/2020
For example,
Input:
day = 21
mnth = 07
year = 2010

Output:
Today is 21/07/2010

Good luck guys!

#Write a Python program that accepts day, month and year from the user and prints the result in this form

#prompt user to input dates
day=eval(input("day"wink)
mnth=eval(input("mnth"wink)
year=eval(input("year"wink)

#display output
print(day,"/",mnth,"/",year)
Re: Python 3: Exercises And Solutions. by Brukx(m): 11:34am On May 01, 2020
Taofeekdboy:

I saw this late, I have been busy with my project and it took a lot of my time.
I will leave it here for who is interested to check..
It is a social media clone I made.
http://mysocialapp.pythonanywhere.com

Looking forward to your comments
How did you get a server?
Re: Python 3: Exercises And Solutions. by Brukx(m): 11:37am On May 01, 2020
jayphe:

Collinsanele Taofeekdboy kensmoney Daddyshome Zabiboy

hmm....who else ooo? Let's get to business. Pls, let's try to read the question in details first. If the question asks for the users' input, then we should include an input statement. Zabiboy we need to talk ooo. This one wey I no see you....


Exercise 4
We are doing some 'loop and looping stuffs' today.


Write a Python program that accepts the name of a student, matric number, course code and the score he/she got in the course. E.g
Name: John Alfred
Matric. No.: MUC/CS/014/0882
Course Code: CMP 212
Score: 100

The program then print the result as:
John Alfred, MUC/CS/014/0882, CMP 212, Grade A


Using this grading table.
100-95 A
94-85 B
84-70 C
69-60 D
59-50 E
49-0 F

Corrections, advices, suggestions and opinions are highly welcome!
what should be the inputable variables in this program?
Re: Python 3: Exercises And Solutions. by Brukx(m): 11:49am On May 01, 2020
jayphe:

Exercise 6
Write a Python program that accepts an integer number and checks if it is an even number or an odd number. Pls don't use the % (modulus) operator. Let's see some genuius.

#prompt user to enter number
number=eval(input("input number:"wink)

if number/2==0:
print("The number is even"wink

else:
print("The number is odd"wink

Nairaland will likely modify some of the codes into smiley
Re: Python 3: Exercises And Solutions. by SKYQUEST(m): 6:49pm On May 01, 2020
Collinsanele:


Where can I get the dataset

HERE

Re: Python 3: Exercises And Solutions. by yemyke001(m): 2:15am On May 04, 2020
SKYQUEST:
Great job guys!

Write a python program where python LOOKS FOR Total Assets and Total liabilities in the attached table and returns the value of the ratio of the two given variables as per their values in the table.

import pandas as pd
df = pd.read_excel('naira.xlsx')
t_assets= df[df.iloc[:,0]=='Total Assets'].iloc[:, 1].values
t_liabilities=df[df.iloc[:,0]=='Total Liabilities'].iloc[:,1].values
print(f'The ratio of total_assets to total_liabilities is {t_assets} : {t_liabilities} which is equal to:', (t_assets/t_liabilities))
Re: Python 3: Exercises And Solutions. by yemyke001(m): 2:17am On May 04, 2020
Using python xlrd library:
import xlrd
f = xlrd.open_workbook('naira.xlsx')
file=f.sheet_by_index(0)
total_a =file.cell_value(8,1)
total_l=file.cell_value(17,1)
print(f'The ratio of total_assets to total_liabilities is {total_a} : {total_l} which is equal to: ',total_a/total_l)
Re: Python 3: Exercises And Solutions. by jayphe(m): 11:41am On May 09, 2020
Phew!! I'm sorry for that long break. I know many people for don vex. I'm sorry. I'm back with an exercise but this one is kinda simple.
Exercise 7
Write a Python program that accepts data from the user be it integer, string, char, float or double. The program stores these in a container/array (list or tuple)


Finally, the program accepts an index from the user and uses the index to find the respective element if the array created. The program then prints the result.e.g.,
Let's say a user inputs the following:
Sam
12
Ben
Lagos
22
Tolu


The user then input 3 as the index, the program must return 'Ben' as the output.


Collinsanele Taofeekdboy kensmoney Daddyshome Zabiboy and lots more...lol!
Re: Python 3: Exercises And Solutions. by Collinsanele: 3:58pm On May 09, 2020
jayphe:
Phew!! I'm sorry for that long break. I know many people for don vex. I'm sorry. I'm back with an exercise but this one is kinda simple.
Exercise 7
Write a Python program that accepts data from the user be it integer, string, char, float or double. The program stores these in a container/array (list or tuple)


Finally, the program accepts an index from the user and uses the index to find the respective element if the array created. The program then prints the result.e.g.,
Let's say a user inputs the following:
Sam
12
Ben
Lagos
22
Tolu


The user then input 3 as the index, the program must return 'Ben' as the output.


Collinsanele Taofeekdboy kensmoney Daddyshome Zabiboy and lots more...lol!

Shouldn't Lagos have an index of 3 from your example
Re: Python 3: Exercises And Solutions. by Zabiboy: 4:35pm On May 09, 2020
Collinsanele:


Shouldn't Lagos have an index of 3 from your example

Index numbers start from 0
Re: Python 3: Exercises And Solutions. by yemyke001(m): 7:15pm On May 09, 2020
jayphe:
Phew!! I'm sorry for that long break. I know many people for don vex. I'm sorry. I'm back with an exercise but this one is kinda simple.
Exercise 7
Write a Python program that accepts data from the user be it integer, string, char, float or double. The program stores these in a container/array (list or tuple)


Finally, the program accepts an index from the user and uses the index to find the respective element if the array created. The program then prints the result.e.g.,
Let's say a user inputs the following:
Sam
12
Ben
Lagos
22
Tolu


The user then input 3 as the index, the program must return 'Ben' as the output.


Collinsanele Taofeekdboy kensmoney Daddyshome Zabiboy and lots more...lol!

data = [val for val in input().split(',')]
index_ = int(input())
print(data[index_])
Meanwhile python indexing start from 0
Re: Python 3: Exercises And Solutions. by Daddyshome: 7:56am On May 10, 2020
jayphe:
Phew!! I'm sorry for that long break. I know many people for don vex. I'm sorry. I'm back with an exercise but this one is kinda simple.
Exercise 7
Write a Python program that accepts data from the user be it integer, string, char, float or double. The program stores these in a container/array (list or tuple)


Finally, the program accepts an index from the user and uses the index to find the respective element if the array created. The program then prints the result.e.g.,
Let's say a user inputs the following:
Sam
12
Ben
Lagos
22
Tolu


The user then input 3 as the index, the program must return 'Ben' as the output.


Collinsanele Taofeekdboy kensmoney Daddyshome Zabiboy and lots more...lol!
Are the inputs on the same line?
Re: Python 3: Exercises And Solutions. by Cuterboy(m): 8:13am On May 10, 2020
Collinsanele:


I am afraid you are not correct.
Coding is not about syntax but thinking and problem solving.

If you write a program to solve a quadratic equation and it fails, you simply debug it and try again, that's testing, you must not be correct in one go.

And Nigerians have good coders fyi
Do you even understand the syntax he's talking about?
Like x^2 + 5x -6 or \sqrt(5x²)
http://9jababa.com/junior-maths-are-you-sure-you-can-solve-this-simple-junior-maths/
Re: Python 3: Exercises And Solutions. by jayphe(m): 7:57pm On May 10, 2020
Thanks for the opinion. I was talking in view of the user. I know the index starts from 0. You wouldn't expect the user to type 4 and the program return the 3rd value he entered.
Re: Python 3: Exercises And Solutions. by Zabiboy: 8:31pm On May 10, 2020
Then use index+1 in your code
Re: Python 3: Exercises And Solutions. by Hotspotbro(m): 1:08pm On May 11, 2020
#project of Hotspotbro
print('Welcome to Whoop, our New social media site')
Name=input('Enter your Email address')
Password=input('Enter your choice password >')
Re: Python 3: Exercises And Solutions. by SKYQUEST(m): 3:25pm On May 22, 2020
yemyke001:


import pandas as pd
df = pd.read_excel('naira.xlsx')
t_assets= df[df.iloc[:,0]=='Total Assets'].iloc[:, 1].values
t_liabilities=df[df.iloc[:,0]=='Total Liabilities'].iloc[:,1].values
print(f'The ratio of total_assets to total_liabilities is {t_assets} : {t_liabilities} which is equal to:', (t_assets/t_liabilities))

nice job sir.
Re: Python 3: Exercises And Solutions. by chitunelee(m): 5:42pm On May 22, 2020
Nyc job guys. I'm kinda new in programming can you guys help me with the benefits python has over other languages
Re: Python 3: Exercises And Solutions. by yemyke001(m): 6:03pm On May 22, 2020
SKYQUEST:


nice job sir.

Thanks boss
Re: Python 3: Exercises And Solutions. by SKYQUEST(m): 12:06pm On May 23, 2020
what python code would you run on a table with data separated by spaces as shown in the image below to convert it in into a readable excel table; the raw data is also given in the attachment below (ben2):

Re: Python 3: Exercises And Solutions. by nwele2017: 12:54pm On May 23, 2020
SKYQUEST:
what python code would you run on a table with data separated by spaces as shown in the image below to convert it in into a readable excel table; the raw data is also given in the attachment below (ben2):

Using Pandas read it in as CSV then convert it to xlsx using data name .to_excel.(ie. name of data .yo_excel("name.xlsx"wink
Re: Python 3: Exercises And Solutions. by SKYQUEST(m): 1:38pm On May 24, 2020
nwele2017:


Using Pandas read it in as CSV then convert it to xlsx using data name .to_excel.(ie. name of data .yo_excel("name.xlsx"wink

can you read this as CSV, will it work?, methinks the file is not comma separated file.
Re: Python 3: Exercises And Solutions. by gbolly1151(m): 3:29pm On May 24, 2020
SKYQUEST:


can you read this as CSV, will it work?, methinks the file is not comma separated file.

I think read_csv take optional argument delimiter which can be comma,using spaxe should work
Re: Python 3: Exercises And Solutions. by Sunijacks(m): 4:23pm On May 24, 2020
How long does it take to learn and become this good with python?
Re: Python 3: Exercises And Solutions. by gbolly1151(m): 4:40pm On May 24, 2020
Reserve
Re: Python 3: Exercises And Solutions. by HappyPagan: 12:30am On May 25, 2020
Nice thread. Hope I'm not too late to the party. Let me start from the beginning.
Re: Python 3: Exercises And Solutions. by HappyPagan: 12:34am On May 25, 2020
jayphe:


Exercise 1


Write a python program that obtains the domain name (thapar.edu) from the URL

http://www.thapar.edu/index.php/about-us/mission

url = "https://www.makeuseof.com/tag/browser-text-based-games/"

fullStopIndex = url.find('.')
forwardSlashIndex = url[fullStopIndex:].find('/')

domain = url[fullStopIndex + 1:fullStopIndex + forwardSlashIndex]
print(domain)


Code snippet here
Re: Python 3: Exercises And Solutions. by HappyPagan: 12:42am On May 25, 2020
jayphe:

Write a Python program that accepts a string/sentence from the user. The program then changes all spaces to underscores. Finally, it prints out the final result.



userInput = input('Enter a sentence: ')

output = ''

for c in userInput:
if c==' ':
output = output + '_'
continue

output = output + c

print(output)


Code snippet
Re: Python 3: Exercises And Solutions. by HappyPagan: 12:49am On May 25, 2020
jayphe:


Write a Python program that accepts day, month and year from the user and prints the result in this form:
Today is 23/04/2020


day = input('Enter a day (1-30): ')
month = input('Enter a month (1-12): ')
year = input('Enter a year: ')

print(f'Today is {day}/{month}/{year}')


(1) (2) (3) (4) (5) (6) (Reply)

Is This What Big IT Firms Do? Please Help Me Out Nairaland Programmers / What Programming Language Is Used In Building PES? / Lets Post Ideas Here 4 Other Programmers

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 44
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.