我写代码。
函数def中的if语句。
我不知道为什么答案总是“是”
假设我们键入“ n”
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class KOTH_ZoneRandom : MonoBehaviour
{
int Rand;
int Length = 4;
List<int> list = new List<int>();
void Start()
{
list = new List<int>(new int[Length]);
for (int j = 1; j < Length; j++)
{
StartCoroutine(loopDelay());
Rand = Random.Range(1, 4);
while (list.Contains(Rand))
{
Rand = Random.Range(1, 4);
}
list[j] = Rand;
print(list[j]);
}
}
IEnumerator loopDelay ()
{
print("started delay");
yield return new WaitForSeconds(60);
}
}
答案 0 :(得分:1)
通过不区分大小写,可以简化它
a = input('Yes or No Type [Y/N]')
def test():
global a
if a.lower() == 'y': #this will convert the string into lower case
print("yes")
elif a.lower() == 'n':
print("no")
else:
print("Not Yes and Not No")
test()
答案 1 :(得分:0)
尝试以下方法使其更强大:
yes = ['Y' , 'y' , 'yes' , 'YES', 'Yes']
no = ['N' , 'n' , 'NO', 'No', 'no']
if answer in yes:
print("yes")
if answer in no:
print("no")
答案 2 :(得分:0)
yes = ['y', 'yes']
no = ['n', 'no']
if answer.lower() in yes:
print("yes")
if answer.lower() in no:
print("no")