Κονσόλα#

Εισαγωγή#

Η Κονσόλα VEXcode εμφανίζεται στο παράθυρο Monitor (Παρακολούθηση) μέσα στο VEXcode. Οι μέθοδοι κονσόλας μπορούν να εμφανίσουν κείμενο, αριθμούς και τιμές μεταβλητών ενώ εκτελείται ένα έργο. Μπορούν επίσης να καθαρίσουν την Κονσόλα, να ορίσουν το χρώμα του κειμένου που εκτυπώνεται μετά την αλλαγή του χρώματος και να παρακολουθήσουν μεταβλητές ή τιμές αισθητήρα στην καρτέλα Monitor (Παρακολούθηση) του VEXcode.

Όταν χρησιμοποιείτε τον κώδικα VS, η έξοδος της κονσόλας που βασίζεται σε κείμενο εμφανίζεται στο τερματικό αντί για την καρτέλα κονσόλας VEXcode.

Παρακάτω είναι μια λίστα με όλες τις μεθόδους:

Ενέργειες — Εξαγωγή κειμένου ή εκκαθάριση της Κονσόλας.

  • print — Displays text, numbers, or variable values in the Console or terminal.

  • new_line — Moves the Console cursor to the start of the next row.

  • clear — Clears all rows in the Console.

Getter — Ανάγνωση εισόδου χρήστη.

  • input — Waits for user input and returns the response as text.

Mutator — Μορφοποίηση εκτυπωμένου κειμένου.

Ενέργειες#

print#

print displays text, numbers, or variable values in the Console. In VS Code, print displays output in the terminal.

Χρησιμοποιήστε προσαρμοσμένη μορφοποίηση συμβολοσειράς όταν θέλετε ένα εκτυπωμένο μήνυμα να περιλαμβάνει τιμές από το έργο σας, όπως μια βαθμολογία, ένα χρονόμετρο ή μια ένδειξη αισθητήρα. Ανατρέξτε στη σελίδα Μορφοποίηση συμβολοσειράς για περισσότερες πληροφορίες.

By default, each brain.print() statement ends with \n, which stands for a new line. This moves the cursor to the next line after the value is printed. The optional end parameter changes what is added after the printed value.

Usage:
brain.print(value, end=“\n”)

Παράμετροι

Περιγραφή

value

Το κείμενο, ο αριθμός ή η τιμή μεταβλητής που θα εμφανίζεται στην Κονσόλα ή στο τερματικό.

end

Optional. The text added after value is printed. The default is “\n”, which moves the cursor to the next line. Use end=“” to keep the next printed value immediately after the previous value on the same line. Use another string, such as end=”, “, to add text between printed values.

# Display two messages on separate lines
brain.print("Hello, CTE!")
brain.print("This prints on the next line.")

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Hello, CTE!" που εμφανίζεται στην πρώτη γραμμή και το "This prints on the next line" στην γραμμή από κάτω.

# Display two messages on the same line
brain.print("Hello,", end=" ")
brain.print("CTE!")

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Γεια σου, CTE!".

# Print three colors on one line, separated by commas
colors = ["Red", "Green", "Blue"]

for color in colors:
    brain.print(color, end=", ")

Εμφανίζεται η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Κόκκινο, Πράσινο, Μπλε".

new_line#

new_line moves the cursor to column 1 on the next row in the Console. The next value printed will appear on that row.

Use this method when you want the next printed value to start on a new row. If this method is not used, and the previous brain.print() statement used end=“” or another value that does not include \n, the next printed value will appear immediately after the previous value on the same row.

Usage:
brain.new_line()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Print on two lines
brain.print("Row 1", end="")
brain.new_line()
brain.print("Row 2")

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Row 1" που εμφανίζεται στην πρώτη γραμμή και "Row 2" στη δεύτερη γραμμή.

clear#

clear clears all rows from the Console.

Usage:
brain.clear()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display text, then clear it after two seconds
brain.print("This will disappear...")
wait(2, SECONDS)
brain.clear()

Λήπτης#

input#

input displays an optional prompt message, waits for the user to enter a response, then returns that response as text.

The project pauses at input() until a response is entered in the Console. In VS Code, the response is entered in the terminal.

The value returned by input() is always text. To use the response as a number, convert it first with int() or float().

Usage:
input(prompt)

Παράμετρος

Περιγραφή

prompt

Προαιρετικό. Μια συμβολοσειρά που θα εμφανίζεται στην Κονσόλα ή στο τερματικό πριν από την αναμονή για απάντηση. Εάν δεν περιλαμβάνεται καμία προτροπή, δεν εμφανίζεται κανένα μήνυμα πριν από την αναμονή.

# Ask for a name, then print a greeting
answer = input("What's your name?")
brain.print("Hello, " + answer)

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Πώς σε λένε;" ακολουθούμενο από ">>> VEX" και από κάτω, "Γεια σου VEX"

# Ask for a number, then use it in math
answer = input("Enter a number:")
number = float(answer)
brain.print(number + 1)

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και το κείμενο "Εισαγάγετε έναν αριθμό:" ακολουθούμενο από ">>> 4" και από κάτω, "5.0"

Μεταλλακτής#

set_print_color#

set_print_color sets the color used for text printed in the Console after this method is used. At the start of a project, the Console text color is set to BLACK.

Αυτή η μέθοδος αλλάζει το χρώμα κειμένου στην κονσόλα VEXcode. Στο VS Code, η υποστήριξη χρωμάτων τερματικού μπορεί να διαφέρει ανά τερματικό.

Usage:
brain.set_print_color(color)

Παράμετροι

Περιγραφή

color

The color to use for text printed in the Console:

  • BLACK
  • BLUE
  • GREEN
  • RED

# Print text in different colors
brain.print("Default text color")
brain.new_line()
brain.set_print_color(RED)
brain.print("Red text color")

Η Κονσόλα VEXcode, που εμφανίζει την Κονσόλα και μαύρο κείμενο που λέει "Προεπιλεγμένο χρώμα κειμένου" στην πρώτη γραμμή και κόκκινο "Κόκκινο χρώμα κειμένου" στη δεύτερη γραμμή.