Jump to content

Hi

I have got a raspberry pi and want to start making programs on it and python is installed as default so i started there.

i was doing python on code academy and had to use .isalpha, is this still in the latest version because i know raw_input was change to input.

Can someone please put some example code of using loop/repeat

Is there a shorter way of doing say

If num == "1" or "2" or "3" or "4:

I would be very greatful as i am learing from scratch

Thanks

Link to comment
https://linustechtips.com/topic/51482-python-help/
Share on other sites

Link to post
Share on other sites

Hi

I have got a raspberry pi and want to start making programs on it and python is installed as default so i started there.

i was doing python on code academy and had to use .isalpha, is this still in the latest version because i know raw_input was change to input.

Can someone please put some example code of using loop/repeat

Is there a shorter way of doing say

If num == "1" or "2" or "3" or "4:

I would be very greatful as i am learing from scratch

Thanks

Link to comment
https://linustechtips.com/topic/51482-python-help/#findComment-687562
Share on other sites

Link to post
Share on other sites

Desk: monitors 3x Asus VE248h(eyefinity), Keyboard Cm Strom Trigger(mx red), Mouse Corsair m65, Headset Audio Technica ATH-M50

Black Friday 2013 Build: i7 4770k, Gigabyte Z87X UD5H, 16gb Corsair, Msi R9 290, Corsair Axi 760, Corsair 750D, 2x intel 530 240gb ssd, 2x Seagate 400gb

Older Machine amd x640, msi 760g mobo, 8gb gskillz, Sapphire 6870, Corsair hx650, Cooler master haf 922, ocz agility 3 120gb ssd || HTPC: i7 3770k, shuttle xpc z77, 16gb gskillz, Asus GTX 650 ti, intel 120gb msata ssd

Link to comment
https://linustechtips.com/topic/51482-python-help/#findComment-687583
Share on other sites

Link to post
Share on other sites

please don't double post or triple post for that matter

| 3570k @ 4.4.ghz | Hyper 212 evo | 8GB (2x4GB) 1600mhz Corsair Vengeance | Gigabyte Z77X UD3H | Corsair CX750M | Corsair 300R | OCZ 240GB SSD | Seagate 1TB 7200rpm HDD | Asus DCUII 7950 @1150mhz core 1600mhz mem

| BenQ XL2411T | Corsair Vengeance K60 | Logitech G700 | steelseries Qck+ | Fiio E10 | Zalman clip on mic | HD 598 | ATH-M50 |

 

Link to comment
https://linustechtips.com/topic/51482-python-help/#findComment-687592
Share on other sites

Link to post
Share on other sites

http://docs.python.org/2/tutorial/controlflow.html

 

Read through the Python documentation - they're beyond excellent. Dive into Python is also excellent: http://www.diveintopython.net/toc/index.html - 100% free.

Interested in Linux, SteamOS and Open-source applications? Go here

Gaming Rig - CPU: i5 3570k @ Stock | GPU: EVGA Geforce 560Ti 448 Core Classified Ultra | RAM: Mushkin Enhanced Blackline 8GB DDR3 1600 | SSD: Crucial M4 128GB | HDD: 3TB Seagate Barracuda, 1TB WD Caviar Black, 1TB Seagate Barracuda | Case: Antec Lanboy Air | KB: Corsair Vengeance K70 Cherry MX Blue | Mouse: Corsair Vengeance M95 | Headset: Steelseries Siberia V2

 

 

Link to comment
https://linustechtips.com/topic/51482-python-help/#findComment-687595
Share on other sites

Link to post
Share on other sites

Hi

I have got a raspberry pi and want to start making programs on it and python is installed as default so i started there.

i was doing python on code academy and had to use .isalpha, is this still in the latest version because i know raw_input was change to input.

Can someone please put some example code of using loop/repeat

Is there a shorter way of doing say

If num == "1" or "2" or "3" or "4:

I would be very greatful as i am learing from scratch

Thanks

Hi and welcome to the forum!

 

I am not sure if Raspberry Pi programming is anything different than stock but you can use a loop to test if a string is equal to several possible outcomes. You can do it using a for loop, the structure of it is

"for (enter the name of a string here) in range (start of range, end of range)". This is perfect for what you're looking for as the cycle counts up in ones and you can use this cycle counter by the name of the string. Here below is an example code of pretty much exactly what you'll want.

for counter in range (1,5):    if num==counter:        #code of what to do here        break

You need the end of the range to be 1 higher than what you want it to end on as it will cycle up to one below the number (someone correct me if I'm wrong, but that's how it treats the cycle number). The break feature is not necessary but will make things more efficient if you are comparing it to say 100 numbers. I will tell you however it is not shorter for the program just simpler than you writing it all out!

 

Good luck with your Python, if you need more help or any in the future just PM me and I'll try to help!

 

EDIT:

I've just realized you said its in an outdated version of Python, if it doesn't support for loops then sorry my bad, but if you can use while I can show you how to do it with that.

| Cooler Master HAF 912 Plus | MSI P67A-G45 | i5 2500K @ 4.2GHz |  Coolermaster Hyper 212 Plus | EVGA GTX 670 FTW Edition 2GB | 8GB (2X4GB) Mushkin Blackline @ 1600MHz | 256GB OCZ Vertex 4 SSD | 1TB Western Digital Caviar Green | Corsair 600CX V2 | Windows 7 64-bit |

Link to comment
https://linustechtips.com/topic/51482-python-help/#findComment-692099
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×