3 Replies - 483 Views - Last Post: 30 January 2012 - 08:47 PM Rate Topic: -----

Topic Sponsor:

#1 dragonballz_ff  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 25-January 12

Only able to input certain number of times. Why?

Posted 25 January 2012 - 01:09 AM

I am new to programming and I was working on this program and for this piece of code I can only input a number a certain amount of times until it says "could not convert to string" when run in the debugger. When the CLS is uncommented only 2 inputs would be allowed until this error would come but when commented 14 inputs are allowed. Why would this be happening? Thanks a lot for your help. Here is my code
while(difference != count):
    number = str(number)
    grade = float(raw_input("Enter course grade for course # " + number + ": "))
    Grades.append(grade)
    difference += 1
    number = int(number)
    number += 1
    #os.system("CLS")



I have also attatched the full program for refernce. Thanks a lot.

Is This A Good Question/Topic? 0
  • +

Replies To: Only able to input certain number of times. Why?

#2 Simown  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 233
  • View blog
  • Posts: 455
  • Joined: 20-May 10

Re: Only able to input certain number of times. Why?

Posted 25 January 2012 - 05:40 AM

Can you please post the full error message verbatim, and the inputs you are using. Which bit "cannot be converted to string"? There are several casts in that program.
Was This Post Helpful? 0
  • +
  • -

#3 wordswords  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 36
  • View blog
  • Posts: 163
  • Joined: 17-December 11

Re: Only able to input certain number of times. Why?

Posted 25 January 2012 - 04:59 PM

I would say that the os.system() call is interfering with your raw_input call. 'CLS' is the windows command to clear the screen.

Why not do this?
1	while(difference != count):
2	    number = str(number)
3	    grade = float(raw_input("Enter course grade for course # " + number + ": "))
4	    Grades.append(grade)
5	    difference += 1
6	    number = int(number)
7	    number += 1
8	os.system("CLS")



That above code mean the screen is cleared only once the while loop has finished processing.

If you want to let users input without it being shown on the screen at all for security purposes, try the getpass function - http://docs.python.o...ry/getpass.html
Was This Post Helpful? 0
  • +
  • -

#4 deviljeon  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 8
  • Joined: 29-January 12

Re: Only able to input certain number of times. Why?

Posted 30 January 2012 - 08:47 PM

I think he's right...
Indention is important in python and a single mistake would ruin the whole program(well, based from my experience) :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1