match signal:
case “red”:
print(“Stop”)
case “yellow”:
print(“Slow down!”)
case “blue” | “green”:
print(“Go!”)
case _:
print(“Invalid signal color…”)
投稿者: chosuke
python elif条件分岐
signal = input(“Signal color?”)
if signal == “red”:
print(“Stop!”)
elif signal == “yellow”:
print(“Slow down!”)
elif signal == “blue” or signal == “green”:
print(“Go!”)
else:
print(“Invalid signal color…”)
C++ fizzbuzz
// 04-fizzbuzz1.cpp : このファイルには ‘main’ 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
include<iostream>
using namespace std;
int main()
{
for (int i = 1; i <= 100; ++i) {
if (i % 3 == 0) cout << “Fizz”;
if (i % 5 == 0) cout << “Buzz”;
if (i % 3 != 0 && i % 5 != 0) cout << i;
cout << endl; } }
}
}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー
// 作業を開始するためのヒント:
// 1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します
// 2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
// 3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
// 4. エラー一覧ウィンドウを使用してエラーを表示します
// 5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
// 6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します
C++ for文
// 04-for2.cpp : このファイルには ‘main’ 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
include
using namespace std;
int main()
{
for (int i = 0; i < 5; ++i) {
if (i == 2) break;
cout << “Hello World!\n”;
}
}
// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー
// 作業を開始するためのヒント:
// 1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します
// 2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
// 3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
// 4. エラー一覧ウィンドウを使用してエラーを表示します
// 5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
// 6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します
Python 論理演算子
論理演算子
and なおかつ
ore もしくは
not ~ではない
eng_score = int(input(“English Score?”))
math_score = int(input(“Math Score?”))
#if eng_score == 100 or math_score == 100:
if not (eng_score == 0 or math_score == 0):
print(“OK!”)
else:
print(“NG!”)
C# おにゃんこ大戦争
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CharactorMove : MonoBehaviour
{
public enum TYPE
{
PLAYER,
ENEMY,
}
public TYPE type = TYPE.PLAYER;
float direction;
Vector3 pos;
bool isMove = true;
// Start is called before the first frame update
void Start()
{
switch(type)
{
case TYPE.PLAYER:
//Player時の処理
direction = -1;
break;
case TYPE.ENEMY:
//Enemyの時の処理
direction = 1;
break;
}
pos = new Vector3(direction, 0, 0);
}
// Update is called once per frame
void Update()
{
if(isMove)
{
transform.position += pos * Time.deltaTime;
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
//敵にぶつかったら移動とめる
if(collision.gameObject.tag == "Enemy" && type == TYPE.PLAYER
|| collision.gameObject.tag == "Player" && type == TYPE.ENEMY)
{
isMove = false;
}
//攻撃をしはじめる
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.gameObject.tag == "Enemy" && type == TYPE.PLAYER
|| collision.gameObject.tag == "Player" && type == TYPE.ENEMY)
{
isMove = true;
}
}
}
Python 条件分岐
条件分岐
#if
score = int(input(“Score? “))
比較演算子
if score > 80:
print(“OK!”)
print(“Good Job”)
else:
print(“NG!”)
print(“Nice try!”)
print(“End of program …”)
C++ for文
// for.cpp : このファイルには ‘main’ 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
include<iostream>
using namespace std;
int main()
{
for (int i = 0; i < 5; ++i) cout << “Hello, World\n”;
}
C++ Swich
include<iostream>
using namespace std;
int main() {
int n = 5;
switch (n % 3) {
case 0:
cout << “3の倍数です。\n”;
break;
case 1:
cout << “3で割った余りは1です\n”;
break;
case 3:
cout << “何かがおかしいです。\n”;
break;
}
}
C++ 制御文
include<iosteram>
using namespace std;
int main(){
int n = 5;
if(n % 2 == 1) cout << “nは奇数です。\n”;
}
