Member Avatar for powerade661

So I am trying to self teach myself Python, and so far it is working great. However I have ran into a bump in the road and can't really figure out why this script isn't working... Any ideas?

import os
answer = raw_input('Ready for shutdown, continue?')
if answer == raw_input('Yes'):
os.system("shutdown -s -t 0")
else (return)

Thanks,
Powerade661

Recommended Answers

All 3 Replies

Change it to

import os
answer = raw_input('Ready for shutdown, continue?')
if answer == 'Yes':
     os.system("shutdown -s -t 0")

First of all, you are trying to ask for two inputs and check whether the two input are the same. What you want to do is getting only one input and check if the input is a string "Yes".

Secondly, Indentation in Python has meaning. Anything inside the condition must be one indentation depth than the condition code.

Member Avatar for powerade661

I feel so dumb... lol What about the else (return) ? How would I make it so that if anything besides yes was entered, it would do nothing and reply back with a message such as "Ok I will not shutdown just yet." ? Any other resources besides Python's website to help me better grasp this?

Thanks again,
Powerade661

Member Avatar for powerade661

Never mind I figured it out. Thanks anyway

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.