Printing strings.. help.. - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Printing strings.. help.. (/thread-3358.html) |
Printing strings.. help.. - zepel - May-17-2017 My first defined function works, however I can't get my second defined function to work. I need my main function to access the upperCase function and then print everything in all caps. For example the user enters in hi, I need my program to convert that to HI. For the love of god I can't figure out where I am going wrong. Can anybody show me? Thanks. Also, how can I get my program to run nonstop? I'm kind of new with looping. def reverse(text): rev_text = "" for i in text: rev_text = i + rev_text return rev_text def upperCase(text1): text1 = s.upper() return text1 def main(): text = str(input("Enter a text: ")) print(reverse(text)) text1 = str(input("Enter a number again: ")) print(upperCase(text1)) main() RE: Printing strings.. help.. - metulburr - May-17-2017 string splicing and string methods >>> 'reverse'[::-1] 'esrever' >>> 'uppercase'.upper() 'UPPERCASE'loop while True: #do something repetitive ie. your code here if condition to quit: break RE: Printing strings.. help.. - zepel - May-17-2017 My program works, please tell me what you think and if I should change anything? def reverse(text): return text[::-1] def upperCase(text2): return text2.upper() def hyphens(text3): return '-'.join(text3.split()) def main(): while True: text = str(input("Enter a text: ")) print(reverse(text)) text2 = str(input("Enter another text: ")) print(upperCase(text2)) text3 = str(input("Enter another text: ")) print(hyphens(text3)) while False: break main() RE: Printing strings.. help.. - nilamo - Aug-14-2017 while False: breakThat does nothing. False will never be True, so the block never runs, and even if it did, all it would do would be to immediately break out of the block, which... does nothing. |