chan 06's Profile
Reputation: 2 Apprentice
- Active Members
- Active Posts:
- 56 (0.13 per day)
- 07-October 12
- Profile Views:
- Last Active:
- Nov 19 2013 05:44 AM
- Dream Kudos:
Posts I've Made
Posted 1 Jul 2013Thank you a lot JackOfAllTrades
Posted 29 Jun 2013I am trying to display each month of the year and the number of days for each month. My code is running 12 times and not sure how to make it run only once.
month = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"] days_Month =[31,28,31,30,31,30,31,31,30,31,30,31] for index in range(len(month)): for index in range(len(days_Month)): print ("%s %3d" % (month[index],days_Month[index])) break
Your program is perfectly fine, you just made a small error. You forgot to add a percent sign % at line 6:
print ('%s %3d' % (month[index],days_Month[index]))
In addition, an addition tip make sure to add brackets when you are printing because in Python 3.x, print() is no longer a statement but a function.
My bad your program has run 144x, repeating twelve times. add a break to the i-loop so that the program only run 12x
(0,0), (0,1), (0,2), (0,3),(0,4), (0,5), (0,6), (0,7), (0,8), (0, 9), (0,10), (0,11), (0,12)
You don't want your i-loop to iterate through one more time. Or else you would get:
(1,0), (1,1)..., (1,12)
Meaning that your program will run one more time.
H Hopefully that made some sense.
Posted 29 Jun 2013Ah thank you so much, took me time to figure out what is Posix-compliant which all you meant is to import the cmath. Sorry for the confusion, I meant in C++ other than that all good.
Posted 19 Jun 2013Hashing is this symbol # that represents comments for your program.
However what you meant was modulus symbol %.
Very basic way to explain is: it is the remainder when you divide two numbers.
An example is:
a = 4 b = 2 print(a%B)/>
You would realize that you will get the value 0 back. Since 4 divide by 2 gives you 2 therefore no remainder is left.
Posted 19 Jun 2013You should look at lines 8-10 because you cannot have 2 else statements. Find the length of your original variable, and if the original variable has length of 0 than print that it is empty. If you need further help post on forums and other people can help you.
- Member Title:
- D.I.C Head
- Age Unknown
- Birthday Unknown
chan 06 hasn't added any friends yet.