Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Printing a string after If statement

python printing string if statement

Best Answer tux, 15 April 2013 - 01:12 PM

Python 3 uses input("Text") to take input from user and returns string.

To take number from user use int(input("Enter text"))

 

Python 2 uses input("Text") for numbers,

raw_input("Text") is used for string

 

In your code you dont need to write 

 

word = str("Cheese")

 

Since the text is inside double quotes Python interprets it as a string. So you don't need to use str()

Line should be

 

word="Cheese"

Go to the full post


This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1 Bitlynk

Bitlynk

    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 15 April 2013 - 11:09 AM

Hi

 

I just cant get this to work.

 

All it does after I enter the password is shutdown. What am I doing wrong?

import time

word = str("Cheese")
	
password = input("Enter password: ")

if password == 1:
        print(word)
        time.sleep(5)
        print("Success")
        time.sleep(1)


#2 tux

tux

    CC Regular

  • Member
  • PipPipPip
  • 29 posts

Posted 15 April 2013 - 01:12 PM   Best Answer

Python 3 uses input("Text") to take input from user and returns string.

To take number from user use int(input("Enter text"))

 

Python 2 uses input("Text") for numbers,

raw_input("Text") is used for string

 

In your code you dont need to write 

 

word = str("Cheese")

 

Since the text is inside double quotes Python interprets it as a string. So you don't need to use str()

Line should be

 

word="Cheese"






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download