tokyo = “JPY”, 36, 140
tokyo = list(tokyo)
tokyo[0] = “YEN”
tokyo = tuple(tokyo)
print(tokyo)
print(tokyo[0])
tokyo = “JPY”, 36, 140
tokyo = list(tokyo)
tokyo[0] = “YEN”
tokyo = tuple(tokyo)
print(tokyo)
print(tokyo[0])
prices = [100, 200, 150, 200, 100]
prices_with_tax = [price * 1.1 for price in prices if price != 200]
print(prices_with_tax)
scores = [10, 20, 30, 20, 40]
scores_sorted = sorted(scores, reverse=True)
print(scores)
print(scores_sorted)
// 04-for2.cpp : このファイルには ‘main’ 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//
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 ファイルを選択します
eng_score = int(input(“English Score?”))
math_score = int(input(“Math Score?”))
if not (eng_score == 0 or math_score == 0):
print(“OK!”)
else:
print(“NG!”)
class Pokemon {
public:
// コンストラクタ
Pokemon(const std::string& nickname) {
this->nickname_ = nickname;
// nickname_ = nickname; と省略できる
}
// デストラクタ
virtual ~Pokemon() {
}
virtual void attack() = 0;
protected:
std::string nickname_;
};
class Pikachu : public Pokemon {
public:
Pikachu(const std::string& nickname) : Pokemon(nickname) {
}
virtual ~Pikachu() {
}
void attack() override {
std::cout << nickname_ << “の十万ボルト!” << std::endl;
}
};
class Zenigame : public Pokemon {
public:
Zenigame(const std::string& nickname) : Pokemon(nickname) {
}
virtual ~Zenigame() {
}
void attack() override {
std::cout << nickname_ << “のハイドロポンプ!” << std::endl;
}
};
int main() {
int i;
Pokemon* monsters[2];
monsters[0] = new Pikachu(“サトシのピカチュウ”);
monsters[1] = new Zenigame(“サトシのゼニガメ”);
std::cin >> i;
if (i >= 0 && i < 2) { monsters[i]->attack();
}
delete monsters[0];
delete monsters[1];
}
initial_balance = int(input(“Initial Balance? “))
RATE = 1.1
print(f”Year 0: {initial_balance:,.2f}”)
print(f”Year 1: {initial_balance * RATE:,.2f}”)
print(f”Year 2: {initial_balance * RATE * RATE:,.2f}”)
class TodoList:
def init(self):
self.tasks = []
def add_task(self, task):
self.tasks.append(task)
def remove_task(self, task):
if task in self.tasks:
self.tasks.remove(task)
else:
print("タスクが見つかりません。")
def list_tasks(self):
if not self.tasks:
print("ToDoリストは空です。")
else:
print("ToDoリスト:")
for idx, task in enumerate(self.tasks, start=1):
print(f"{idx}. {task}")
def main():
todo_list = TodoList()
while True:
print(“\n操作を選択してください:”)
print(“1. タスクを追加”)
print(“2. タスクを削除”)
print(“3. タスク一覧を表示”)
print(“4. 終了”)
choice = input(“選択: “)
if choice == '1':
task = input("タスクを入力してください: ")
todo_list.add_task(task)
print("タスクが追加されました。")
elif choice == '2':
task_idx = int(input("削除するタスクの番号を入力してください: "))
if 1 <= task_idx <= len(todo_list.tasks):
task_to_remove = todo_list.tasks[task_idx - 1]
todo_list.remove_task(task_to_remove)
print("タスクが削除されました。")
else:
print("無効な番号です。")
elif choice == '3':
todo_list.list_tasks()
elif choice == '4':
print("プログラムを終了します。")
break
else:
print("無効な選択です。")
if name == “main“:
main()
int main()
{
std::cout << “Hello, World!\n”;
}
fname = “Taro”
lname = “Yamada”
age = 32
separator = “=-“
print(separator * 10)
print(“I am {}{},{} years old!”.format(fname, lname,age))
print(f” {fname}{lname},{age} years old!”)
print(separator * 10)