The Student Room Group

Python

I need help with this code
Why doesn't it print the statements according to the numbers.
(edited 4 years ago)
Reply 1
Original post by sidick angel
I need help with this code
Why doesn't it print the statements according to the numbers.

I think you need to write int (input in the code as the input is an integer.
Reply 2
i did the dice game for my GCSE course work aswell! (if thats whats your doing)
Try writing choice = int(input(“Enter 1/2/3: “))
Original post by Elsmok
i did the dice game for my GCSE course work aswell! (if thats whats your doing)

yes
I need help with that too.
My subroutine of checking the length of the year is not working in this subroutine. What can I do do make it work please?

so in this if i entered 23 as the year, according to the subroutine, it should have me enter it again and again until it is 4 digits but it doesn't do anything.

can someone help me out please?
Original post by sidick angel
I need help with that too.
My subroutine of checking the length of the year is not working in this subroutine. What can I do do make it work please?

so in this if i entered 23 as the year, according to the subroutine, it should have me enter it again and again until it is 4 digits but it doesn't do anything.

can someone help me out please?


There's two problems - firstly your check only asks the user to enter the year again if the length is greater than 4 digits (23 isn't greater than 4 digits), so that just needs a different bit of logic (If you want it to be exactly 4 digits then you probably want a "not equals" check instead of 'greater/less than')

Secondly, the 'year_chk' function doesn't return the value entered by the user. The 'year' variable inside your year_chk() function is a totally different variable (i.e. exists in a different place in your program's memory) compared with the 'year' variable in your main program -- that's easy to fix, because the function can output that variable just by using return year at the end..

year_chk is already doing some logic which asks the user to enter a year, so it would be better to move put the year = input('Enter a year') inside that function as well. You already need to modify year_chk to return the year. Your main program will need to retrieve the year using year=year_chk(). that makes things neater/tidier by making sure all your 'year' input/checking logic is neatly wrapped up inside year_chk()
(maybe a more accurate name for it then would be input_year() instead)


By the way, I don't know what you're planning to do with your year/month/day, but when Python gets user input it will treat everything that the user inputs as a text strings (character sequences), so if you need to do any numerical calculations or making sure that the date is actually a valid calendar date, you'll have an easier time by convert those into 'int' (integers). Then you can use Python's 'datetime' to take care of checking, so that'll do date/time calculations for you: https://stackoverflow.com/questions/15226898/python-3-2-input-date-function
(edited 4 years ago)
I need help with this code as it stops working the you enter a one digit number. Why is that so as it is supposed to continue until the length of the date is not 2. Can someone please explain that to me please?

Quick Reply

Latest

Trending

Trending