xxxxxxxxxx
if guess in word:
print("\nYes!", guess, "is in the word!")
# Create a new variable (so_far) to contain the guess
new = ""
i = 0
for i in range(len(word)):
if guess == word[i]:
new += guess
else:
new += so_far[i]
so_far = new # unindented this
xxxxxxxxxx
package com.yawintutor;
public class StringSubstringCharAt {
public static void main(String[] args) {
String str = "Bangalore";
String str2;
str2 = str.substring(3, 8);
System.out.println("Given String : " + str);
System.out.println("Output String : " + str2);
}
}
xxxxxxxxxx
try:
# Your code that may cause "Index out of range" error
my_string = "Hello World"
# Trying to access an index that is out of range
character = my_string[20]
print(character) # This line will not be executed if an exception occurs
except IndexError:
# Handling the "Index out of range" error
print("Index out of range error occurred!")
# Perform any necessary actions to handle the error gracefully