1

I am a python developer and I am taking the course to brush up on my C language skills. During the week 2 lecture (continued), David shows how a loop iteration can be used to access indices in a string. I am able to make the following simple script I wrote run on my windows Python IDLE editor + console. However, the same script does not run in the cs50 appliancewith the error

Traceback (most recent call last):
   File "test.py", line 1, in <module>
      s = input("Enter a string: ")
   File "<string>", line 1, in <module>
NameError: name 'This is cs50' is not defined

Here is my script, which takes a user input string and separates the capitalized letters from the lowercase letters using a method similar to the weeks example:

s = input("Enter a string: ")
lower = ''
upper = ''
for char in s:
    if char >= 'a' and char <='z':
        lower += char
    elif char >= 'A' and char <= 'Z':
        upper += char

print(lower)
print(upper)

As I said, this works fine in my windows environment, but not the cs50 appliance. If anyone could figure out why this is exactly, I'd appreciate it!

1 Answer 1

2

The thing wrong with this code is you're using Python 3. When trying to run it on Python 2.7 on windows, it raises the same error, so you should try porting it to the earlier version. This is easily achieved - just change input() to raw_input() and remove the brackets around print

1
  • EDIT: Got it to work using your method! Also, I can invoke python3 in the appliance by typing "python3 test.py" Sep 18, 2015 at 1:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .