Saturday, May 25, 2024

Diploma Python Programming - Module 03 - Alison 03

 Pada Module 03 ini kita akan berbicara tentang string variables, termasuk expecting input dan intro variabel. 



Image - Python programming (credit to Google).


Topik string variable diantara topik menarik dalam Pythpn.

Input string variable
name = input("what is your name? ")
Run Python File:
what is your name?
what is your name? atan

Sekarang, kita masukkan print(name)
name = input("what is your name? ")
print(name)
Run Python File:
what is your name?

what is your name? atan
atan


Variables: firstname + lastname
firstname = input("What is your first name? ")
lastname = input("What is your last name? ")
print("Apa kabar " + firstname + lastname)
Run Python File:
What is your first name?  wak
What is your last name?  atan
Apa kabar  wak atan

space between firstname + " " + lastname
firstname = input("What is your first name? ")
lastname = input("What is your last name? ")
print("Apa kabar " + firstname + " " + lastname)
Run Python File:
What is your first name? wak
What is your last name? atan
Apa kabar wak atan


lower or uppercase
message = "Hello word"
print(message.lower())
print(message.upper())
print(message.swapcase())
Run Python File:
hello word
HELLO WORD
hELLO WORD

Manipulasi Variabel
name = input("What is your name? ")
country = input("What country do you live in? ")
country = country.upper()
print("Hello, " + name + ". You live in " + country)
Run Python File:
What is your name? Atan
What country do you live in? usa
Hello, Atan. You live in USA

Make short story with python program with include age, place etc. Personal story:
story = input("This story was started when I was at age: ")
country = input("On that time, I was live in the country of: ")
fish = input("I catch fish called as: ")

print("This story was started when I was at age " + story + " " + 
"On that time, I was live in the country of " + country + " " + 
"I catch fish called as " + fish + " " + "Good for Asam Pedas") 

story = input("This story was started when I was: ")
country = input("On that time, I was live in: ")
fish = input("I catch fish called as: ")

print("This story was started when I was "
+ story + " " + ", on that time, I was live in "
+ country + " " + ". I catch fish called as "
+ fish + " " + "Good for Asam Pedas")
Run Python File:
This story was started when I was: 13
On that time, I was live in: Indonesia
I catch fish called as: Red Snapper
This story was started when I was 13 , on that time, I was live in Indonesia . I catch fish called as Red Snapper Good for Asam Pedas

Summary Module 3:
For getting input from the user in python you use the input command.
Input is broken into two parts:- A message you specify to display to the user.- User input.

You will use a variable to record the value entered by the user. 

  • Visual Studio has a built in feature called IntelliSense, which will suggest possible functions that you can call after you type the full stop “.”.
  • Programmers do not memorize all the functions, when they need these functions they use IntelliSense to prompt them, they have or get documentation and they can search on the internet.
  • IntelliSense doesn’t always prompt you with a function, because it might not know what you’re going to store in the variable. To get around this you initialize your variable, which means when you create it you give the variable a value.

Next lesson, Module 4.

====================================
====================================

Dave Gray
Free Course: https://www.youtube.com/@freecodecamp

Kita akan belajar Scope in Python.

Scope refers to the areas where variables are visible and accessible within a program. Python utilizes two main types of scope:

  1. Local Scope:

    • Variables created inside a function belong to the local scope of that function. They can only be used within that specific function.

    • For example:

      Python
      def myfunc():
          x = 300
          print(x)
     myfunc()  # Prints 300

2. Global Scope:

  • A variable created outside of any function (in the main body of the Python code) is a global variable. It belongs to the global scope.

  • Global variables are accessible from within any scope, both global and local.

  • Example:

    Python
    x = 300
    
    def myfunc():
        print(x)
    myfunc() # Prints 300
   print(x)  # Also prints 300

Next Lesson (12/24)

JJJJJJJJJJJJJJJ


No comments:

Post a Comment