Python Forum
Printing strings.. help..
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing strings.. help..
#1
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()
Reply
#2
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
Recommended Tutorials:
Reply
#3
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()
Reply
#4
while False:
    break
That 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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Strings inside other strings - substrings OmarSinno 2 3,649 Oct-06-2017, 09:58 AM
Last Post: gruntfutuk

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020