Beginner python practice
-
Well just getting into the flow of thing with Python. Reading a few books, finding it fairly easy as I already have some experience with C++/Java from school and Python is definetly my favorite thus far.
Anyway, I am getting a whole bunch of information on python, but haven't been putting it to much use. Thus, what I was wondering was if there are any sort of practice problems online that I can use? If anyone could point me in any sort of direction, I'd greatly appreciate it.
-
Absolutely!
Pythonista:
- Make a Text-To-Speech App (type and it says it)
- Modify the Speech-To-Text example that is in the documentation to make a "voice note" app (speak and it just writes out the words)
General:
- Use the requests library to show a random joke from api.chucknorris.io (uses JSON)
Notes:
Post your code here and ask folks to review it for you :)
-
Those are all great ideas @reticulated!
-
Oh and for anyone stumbling upon this..
Anyone who knows C, please contribute using ctypes, as well those who know Objective C, some objc_util examples.
Let's try to use our individual strengths to help others!
-
My favorite problem is always to design a game (though, to be fair, game design is the main reason I fell in love with programming in the first place). The app does have a nice Python game tutorial, try following that along and see if you can improve or change the game!
Another challenge: grab text from a website, parse it so you get only relevant information, and output that information in Pythonista. An easy example is take a look at a the Google "I'm feeling lucky" page and see what the result is.
And if you get that challenge down, you can take it a step further. Have the script visit a site with stocks or price ranges, and try to graph those prices in Python! This could be awesome if you're trying to built your own investment tools and want to apply your own algorithms to the graph. There's some good plot examples in the app to get you started on this.
Just some ideas! Have fun and ask yourself "what would I want my device to do, for me?" If it's not impossible then you can probably program it.
-
Here is my Chuck Norris api code:
#!/usr/bin/env python """downloads a random Chuck Norris joke or fact using the api""" import requests import json import ui import console def main(): display_banner() print() console.show_activity() data = get_joke() text = parse_json(data) print(display_joke(text)) # button_tapped(sender) console.hide_activity() def display_banner(): print('-' * 40) print('| Chuck Norris Jokes |') print('-' * 40) def get_joke(): response = requests.get('https://api.chucknorris.io/jokes/random') if response.status_code == 200: print(response.status_code) # rest = response.content else: print("error unable to connect to api\n") print(response.status_code) rest = response.content return rest def parse_json(data): text = json.loads(data) text = (text['value']) # print(text) return text def display_joke(text): formatted = str(text).strip() # print(type(formatted)) return formatted # def button_tapped(sender): # chuck = button_tapped(sender) # sender.title = chuck # view = ui.load_view('chuck') # view.present('full_screen') # return # #view.present('full_screen') if __name__ == '__main__': main()
-
This post is deleted!last edited by
-
This post is deleted!last edited by
-
This post is deleted!last edited by vijaydeveloper
-
Thanks for this great idea.
-
This post is deleted!last edited by
-
You can also check out coding challenges on CheckIO. It's a great platform for python practice, where you can have fun while learning something new, solving interesting tasks and analizing the unique solutions of other users. It's free, friendly and has a lot of tools you can use)