Pyton-2: Unterschied zwischen den Versionen

Aus MeWi
Zeile 19: Zeile 19:
<pre>
<pre>
# reverse a string
# reverse a string
my_name = "Das ist ein Satz."
def reverse_string(my_string):
# uppercase the string
    # uppercase the string
upper_name = my_name.upper()
    upper_string = my_string.upper()
# reverse it with slice
    # reverse it with slice
revers_name = upper_name[::-1]
    reversed = upper_string[::-1]
# how many chars in string?
    # how many chars in string?
tot_chars = len(revers_name)
    tot_chars = len(reversed)
    i = 0
    # loop through all chars
    while i < tot_chars:
        print(reversed[i])
        i += 1
 
 
my_string = "Das ist ein Satz."
reverse_string(my_string)
 
my_string = "Yet another one."
reverse_string(my_string)


i = 0
# loop through all chars
while i < tot_chars:
    print(revers_name[i])
    i += 1
</pre>
</pre>



Version vom 16. November 2024, 12:09 Uhr

008

Lists

# Lists
# array von 1 bis 42
lottozahlen = list(range(1, 43))
print(lottozahlen)

001

Timestamp ausgeben

fff

010

Reverse String

# reverse a string
def reverse_string(my_string):
    # uppercase the string
    upper_string = my_string.upper()
    # reverse it with slice
    reversed = upper_string[::-1]
    # how many chars in string?
    tot_chars = len(reversed)
    i = 0
    # loop through all chars
    while i < tot_chars:
        print(reversed[i])
        i += 1


my_string = "Das ist ein Satz."
reverse_string(my_string)

my_string = "Yet another one."
reverse_string(my_string)

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff

001

Timestamp ausgeben

fff