BeyondPapers
15/05/2022
🔑 PYTHON CHALLENGE #9 (My Palindromic Odometer)
"I was driving on the highway the other day and I happened to notice my odometer. Like most odometers, it shows six digits, in whole miles only. So, if my car had 300,000
miles, for example, I'd see 3-0-0-0-0-0.
"Now, what I saw that day was very interesting. I noticed that the last 4 digits were
palindromic; that is, they read the same forward as backward. For example, 5-4-4-5 is a
palindrome, so my odometer could have read 3-1-5-4-4-5.
"One mile later, the last 5 numbers were palindromic. For example, it could have read
3-6-5-4-5-6, One mile after that, the middle 4 out of 6 numbers were palindromic. And
you're ready for this? One mile later, all 6 were palindromic!
"The question is, what was on the odometer when I first looked?"
Write a Python program that tests all the six-digit numbers and prints any numbers that
satisfy these requirements.
Adapted from Think Python, 2nd Edition
by Allen Downey.
Copyright 2015 Allen Downey
License: http://creativecommons.org/licenses/by/4.0/
Upon getting a satisfactory result, push your code to Github, and post the repository link here.
Creative Commons — Attribution 4.0 International — CC BY 4.0 Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
15/05/2022
🔑 PYTHON CHALLENGE #8 (Spreadsheets)
CSV files are spreadsheets containing Comma Separated Values, that are saved with the .csv file extension.
In a CSV file, neighbouring cells (columns) are basically separated by a delimiting comma (,), while rows are separated by line breaks.
For example, a file prepared in Notepad or Visual Studio Code with the following content:
Member,Surname,Age,Height,Weight
Ali,Abubakar,36 years,171 cm,62 kg
Zira,Ashley,41 years,161 cm,70 kg
Franklin,Olumide,32 years,180 cm,59 kg
Danladi,Muhammed,33 years,168 cm,63 kg
Doris,Chukwuma,36 years,170 cm,71 kg
will display as shown in the image, if saved with the .csv file extension and opened in Microsoft Excel. Wow! Wonderful, huh?
With Python, we can read this file as a plain text, and access its values.
The above (comma separated) list is the record of some 5 members of a team. Create a .csv file with the above content, and write a Python program to access the cells of the spreadsheet for the details of each member.
The program operates by accepting interactive inputs from its user, and processing the input.
If for example, the user enters "Age of Ali", the program prints "36 years". When "Surname of Doris" is entered, the output will be "Chukwuma".
Furthermore, when the input is "Members", the Output is: "Ali, Zira, Franklin, Danladi, Doris", but when "Member 1" is entered, the result is "Ali".
Your program should not process the title row (first row), since it does not hold the record of any person.
What's more? Your program should be flexible enough to accommodate changes, such as new members, changed names etc on the spreadsheet.
Remember to handle exceptions!
Upon testing and debugging your program, push your code and file to Github, and post the repository link here.
Property of BeyondPapers Technologies by Akinpelumi Michael.
© 2020 Michael Akinpelumi, BeyondPapers
License: http://creativecommons.org/licenses/by/4.0/
15/05/2022
🔑 PYTHON CHALLENGE #7 (Calculus)
Differentiating 3x^2 gives 6x, while Integrating the result gives back 3x^2 (+ c).
The Power Rule:
Generally, differentiating a.x^n gives n.a.x^(n-1)
On the other hand, when a.x^n is integrated, the result will be (a/[n+1]).x^[n+1] + c
Where,
x is a mathematical variable
a is the coefficient of x
n is the power of x
c is an arbitrary constant
(A picture from BeyondPapers Workshop 1.0 (2020) has been attached to help you understand the concept better.)
Write a Python program that can differentiate or integrate any given (single variable) mathematical term, such as 3x^2, using the Power Rule. The term must contain only one variable, say x, but not necessarily x. Your program should be able to accept any letter.
It does this by receiving an input (that contains the type of calculus operation and the term) from the user, and gives the following results:
If the input is: "D 3x2"
The output is: "f'(3x^2) = 6x"
(That was Differentiation: Input starts with a "D ")
If the input is: "S 8x3"
The output is: "S (8x3) dx = 2x^4 + c"
(That was Integration: Input starts with an "S ")
Remember certain terms may come with 1 or 0 power of x. Your code should be able to handle this. It should for example, be able to understand an input of '6x' as '6x1' [6x^1] and '12' as '12x0' [12x^0].
Remember to handle exceptions!
Upon completing an extensive test on your new program, push your code to Github, and post the repository link here.
Property of BeyondPapers Technologies by Akinpelumi Michael.
© 2020 Michael Akinpelumi, BeyondPapers
License: http://creativecommons.org/licenses/by/4.0/
🔑 PYTHON CHALLENGE #4 (Binary Numbers)
Create a program that converts X, an integer (in base 10) to a binary number (in base n), where X and n are integers entered by the user.
The program then displays the solution in the form:
➖➖➖➖➖➖➖➖➖➖➖
3 | 7
| 2 r 1
| 0 r 2
:. 7 base 10 = 21 base 3
➖➖➖➖➖➖➖➖➖➖➖
Upon testing and debugging your code, push your code to Github, and post the repository link here.
Click here to claim your Sponsored Listing.