Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
It is a question that I encountered in a competitive programming site. The question asked to return the value count/n

I have attached my codes and I only want to know how to write the return statement. And note that the output should be of the format count/n and not in decimals.

What I have tried:

def printer_error(s):
count = 0
n = len(s)
for i in s:
if i in ["n","o","p","q","r","s","t","u","v","w","x","y","z"]:
count += 1
Posted
Updated 9-Aug-19 22:39pm

did you try this?
Python
return str(count)+"/"+str(n)
 
Share this answer
 
Comments
Member 14517556 10-Aug-19 23:58pm    
Never actually come to my mind. Thank you
Patrice T 11-Aug-19 0:42am    
You're welcome.
If your question is solved, you can accept the answer, it will close the question.
Member 14517556 11-Aug-19 1:11am    
Oh sorry forgot to do so.Thank you again
Patrice T 11-Aug-19 1:30am    
No problem
Um ...
Python
return count/n
 
Share this answer
 
Comments
Member 14517556 10-Aug-19 2:51am    
I think you didn't understood my point. I want return value in fractions and not in decimals. Your code will give return value in decimals.
OriginalGriff 10-Aug-19 3:08am    
The only way to "return a fraction" is to either return two values (which you can) or to return a string made up of the two values.
Python doesn't have a "fractions type"!

I'd suggest going back to your site and reading the instructions really carefully!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900